固定页脚的位置iTextPdf7 - Java

时间:2018-04-16 21:16:23

标签: java pdf itext

我有一个单页A4 pdf由itextpdf7生成,我想修改页脚的位置(这是一个SeparatorLine和两行文本)总是在页面的底部。

这是我的页脚代码:

 public void addFooter(Document layoutDocument) {

    SolidLine line = new SolidLine(1f);
    LineSeparator ls = new LineSeparator(line);
    ls.setHorizontalAlignment(HorizontalAlignment.CENTER);
    ls.setWidth(UnitValue.createPercentValue(70));
    Div div = new Div();
    div.add(ls);
    layoutDocument.add(div);
    Paragraph footerFirstParagraph = new Paragraph();
    footerFirstParagraph.add(new Text("ADRESSE : ").setBold());
    footerFirstParagraph.add(new Text("ADDRESSE HERE"));

    layoutDocument.add(footerFirstParagraph.setFont(pdfTextFont).setTextAlignment(TextAlignment.CENTER)
            .setFontSize(10));

    Paragraph footerSecondParagraph = new Paragraph();
    footerSecondParagraph.add(new Text("3443443: ").setBold());
    footerSecondParagraph.add(new Text("3443443"));
    footerSecondParagraph.add(new Text("344").setBold());
    footerSecondParagraph.add(new Text("34434"));     
    footerSecondParagraph.add(new Text("3443443: ").setBold());
    footerSecondParagraph.add(new Text("3443443"));   
    footerSecondParagraph.add(new Text("3443443: ").setBold());
    footerSecondParagraph.add(new Text("3443443"));

    layoutDocument.add(footerSecondParagraph.setFont(pdfTextFont).setTextAlignment(TextAlignment.CENTER)
            .setFontSize(10));      
}

1 个答案:

答案 0 :(得分:0)

经过一些试验,我找到了答案。

Div div = new Div();
div.add(ls);
div.add(footerFirstParagraph);
div.add(footerSecondParagraph);
div.setFixedPosition(float positionFomleft(50), 
                     float positionFromBottom(30),
                     float widthOfDiv (UnitValue.createPercentValue(float val)));
layoutDocument.add(div);