2014-02-19 155 views
1

我试图在iTextSharp(一种在页面底部插入空格和放置文本的方式)中从Latex中找到类似\vfill的东西。这只是一页,而不是页脚。iTextSharp垂直页面填充

我在网上搜索了iText in the Book,但没有找到任何答案。

回答

1

好吧,经过很长时间,并尝试了很多事情,我找到了一个解决方案。

有些事情我想,“工作”,但还不够好:

首先,我计算我的段落的高度(通过在RAM中的新文档中一个新的表写它),然后我会添加新行,直到我的文本有足够的空间。结果:不是一个好的方法,文本会被几个点(文档中的y位置,因为换行符)关闭。

然后我试图用ColumnText来做到这一点:太多的计算(因为我的文档是动态的),我不喜欢把它放在绝对位置。

所以我的解决办法是使用PdfPTable:

  var t = new PdfPTable(1); 
      t.ExtendLastRow = true; 
      t.WidthPercentage = 100; 

      var c = new PdfPCell(); 
      c.VerticalAlignment = Element.ALIGN_BOTTOM; 
      c.DisableBorderSide(Rectangle.BOX); 

      var p = new Paragraph("This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test."); 
      p.Alignment = Element.ALIGN_JUSTIFIED; 

      c.AddElement(p); 

      t.AddCell(c); 

      doc.Add(t); 

很简单,但我失去了很多的时间在这。我希望这也能帮助其他人。