C# iTextSharp 垂直间距

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/875892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:04:04  来源:igfitidea点击:

iTextSharp Vertical Spacing

c#itextsharp

提问by Elie

I'm using iTextSharp to generate some PDF files. I have two tables which have content, and I want to put some space between the two tables, say the equivalent of 1 line of text (using the same font as the tables around the space).

我正在使用 iTextSharp 生成一些 PDF 文件。我有两个包含内容的表格,我想在两个表格之间放置一些空间,比如相当于 1 行文本(使用与空间周围表格相同的字体)。

Below is the code I'm using to add the two tables. What I cannot figure out is how to place a vertical space between the two tables.

下面是我用来添加两个表的代码。我无法弄清楚的是如何在两个桌子之间放置一个垂直空间。

Table upperTable = new Table(1);
upperTable.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
upperTable.AddCell(new Phrase("some text", font3));
d.Add(upperTable);
Table lowerTable= new Table(1);
lowerTable.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
lowerTable.AddCell(new Phrase("some other text", font3));
d.Add(lowerTable);

Can someone tell me how I can add the vertical space between the two tables?

有人能告诉我如何在两个表之间添加垂直空间吗?

Thanks!

谢谢!

采纳答案by Elie

I found a solution that sort of works... add the new lines as part of either the preceding string, or the following string to the space that I want to create. For example:

我找到了一种有效的解决方案...将新行作为前面字符串的一部分或以下字符串的一部分添加到我要创建的空间中。例如:

Table upperTable = new Table(1);
upperTable.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
upperTable.AddCell(new Phrase("some text" + '\n', font3));
d.Add(upperTable);
Table lowerTable= new Table(1);
lowerTable.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
lowerTable.AddCell(new Phrase('\n' + "some other text", font3));
d.Add(lowerTable);

would cause 2 lines whose height is defined by font3to be added between the "some text"and "some other text"

将导致font3"some text"和之间添加高度由 定义的 2 行"some other text"

回答by Eugene Z

Use PdfPTable instead. It has properties SpacingBeforeand SpacingAfter

请改用 PdfPTable。它具有属性SpacingBeforeSpacingAfter

For example:

例如:

PdfPTable upperTable = new PdfPTable(1);
upperTable.AddCell(new Phrase("some text", font3));
upperTable.SpacingAfter = 10f;