如何在iTextSharp \ iText中的两个元素之间添加space \ margin?

时间:2022-04-29 21:13:52

I am pretty new in iTextSharpt (the iText porting for C#) and I have the following doubt.

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

In my code I have something like it:

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

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);

As you can see I simply print a title (usinga Paragraph object) and under it a place a table.

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

The problem is that there is no space (margin) between my title and my table and the graphic result is not good, this is what I obtain in the generated PDF:

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

如何在iTextSharp \ iText中的两个元素之间添加space \ margin?

What can I do to add some space\margin between the title paragraph and the table? What is the best way to do it? I am trying to do it but, untill now, I have found no solution

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

Tnx

TNX

1 个解决方案

#1


41  

You have a couple of different options. You could set the SpacingAfter on your paragraph:

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

titolo.SpacingAfter = 20;

You could also set the SpacingBefore on the table:

您还可以在表格上设置SpacingBefore:

table.SpacingBefore = 20;

Or you could just add some returns to your paragraph:

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

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

#1


41  

You have a couple of different options. You could set the SpacingAfter on your paragraph:

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

titolo.SpacingAfter = 20;

You could also set the SpacingBefore on the table:

您还可以在表格上设置SpacingBefore:

table.SpacingBefore = 20;

Or you could just add some returns to your paragraph:

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

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