iText:标题的自定义左右边距

时间:2014-04-11 10:25:36

标签: pdf layout itext margins

我创建了一个创建pdf文档的java类。该文档有一个由带有文本和图像的表组成的标题,该标题出现在每个页面上。

我将标题放在PdfPageEventHelper.onStartPage(),代码如下:

Document doc = new Document();
ByteArrayOutputStream baos= new ByteArrayOutputStream(); 
PdfWriter writer = PdfWriter.getInstance(doc, baos);
doc.setMargins(Utilities.millimetersToPoints(30), Utilities.millimetersToPoints(20),   Utilities.millimetersToPoints(10), Utilities.millimetersToPoints(15));
writer.setPageEvent(new HeaderFooter(Variables...));
doc.open();

... do other stuffs...

我有以下问题:我希望标题的左右边距不同于文档的其余部分:特别是标题表的左侧应该左侧更靠左侧。

这样做可能吗?我的问题有一个简单的解决方案吗?我阅读了文档,但找不到最简单的解决方案。

2 个答案:

答案 0 :(得分:1)

如果您使用与此example相同的方式实施了HeaderFooter课程,则只需在TableFooter#onEndPage()所见的writeSelectedRows()来电中设置所需的值即可把你的标题放在绝对位置。

答案 1 :(得分:0)

解决:我把标题放在段落中并设置左边距为负... 残酷但有效:)