【问题标题】:How can add space\margin between two elements in iTextSharp\iText?如何在 iTextSharp\iText 中的两个元素之间添加空格\边距?
【发布时间】:2014-05-19 12:11:06
【问题描述】:

我是 iTextSharpt(C# 的 iText 移植)的新手,我有以下疑问。

在我的代码中我有类似的东西:

iTextSharp.text.Paragraph titolo = new iTextSharp.text.Paragraph(currentVuln.Title, _fontTitolo0);
titolo.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
_document.Add(titolo);

table = new PdfPTable(3);
table.WidthPercentage = 98;

cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);

table.AddCell("Col 1 Row 1");
table.AddCell("Col 2 Row 1");
table.AddCell("Col 3 Row 1");
table.AddCell("Col 1 Row 2");
table.AddCell("Col 2 Row 2");
table.AddCell("Col 3 Row 2");

_document.Add(table);

如您所见,我只是打印一个标题(使用 Paragraph 对象)并在其下方放置一个表格。

问题是我的标题和表格之间没有空格(边距),图形效果不好,这是我在生成的PDF中得到的:

如何在标题段落和表格之间添加一些空格\边距?最好的方法是什么?我正在尝试这样做,但是直到现在我还没有找到解决方案

Tnx

【问题讨论】:

    标签: c# asp.net .net itextsharp itext


    【解决方案1】:

    您有几个不同的选择。您可以在段落中设置SpacingAfter

    titolo.SpacingAfter = 20;
    

    你也可以在桌子上设置SpacingBefore

    table.SpacingBefore = 20;
    

    或者你可以在你的段落中添加一些返回:

    iTextSharp.text.Paragraph titolo = new iTextSharp.text.Paragraph("Hello World\n\n");
    

    【讨论】:

      【解决方案2】:

      使用设置的边距来调整页面的填充空间。

      Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); pdfDoc.SetMargins(20f, 20f, 20f, 20f);

      您可以根据需要调整大小值。

      【讨论】:

      • OP 想要在标题和表格之间增加空间,而不是在页面边框和内容之间。
      猜你喜欢
      • 2017-08-09
      • 2020-01-31
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      相关资源
      最近更新 更多