2009-05-18 147 views
5

我正在使用iTextSharp來生成一些PDF文件。我有兩個有內容的表格,我想在兩個表格之間放一些空格,比如說相當於1行文字(使用與空格周圍表格相同的字體)。iTextSharp垂直間距

下面是我用來添加這兩個表的代碼。我無法弄清楚的是如何在兩個表格之間放置一個垂直空間。

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

有人能告訴我如何添加兩個表之間的垂直空間嗎?

謝謝!

回答

2

我找到了一種解決方法,將作品的種類添加到新的行中,作爲前面的字符串的一部分,或者將下面的字符串添加到我想要創建的空間中。例如:

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

將導致2線,其高度由font3定義的"some text""some other text"

12

使用PdfPTable之間添加代替。它具有性能SpacingBeforeSpacingAfter

例如:

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

此問題已在2009年iTextSharp的有`Table`對象,直到版本4.3.x,並從5.x版上,它是`PdfPTable` – 2012-10-16 13:45:41