0

我的问题是我如何使用 iText 1.5.4 添加多行页脚我知道我的问题与这个问题类似,到目前为止这个问题还没有得到回答。此外,我不需要在页脚中使用表格的解决方案。

基本上我想要实现的是这样的 多行的页脚

4

2 回答 2

2

我建议你按照这个例子:

http://itextpdf.com/examples/iia.php?id=103

您将能够添加任何您想要的页眉和页脚。我过去一直在使用它,并且能够在页脚中放置一个表格。

请注意这一点class HeaderFooter extends PdfPageEventHelper以及public void onEndPage(PdfWriter writer, Document document)他们的示例。

希望这可以帮助!

于 2013-03-06T05:59:32.103 回答
0

我使用下面的代码实现了我想要的布局,类似于我在问题中发布的图像。我对 itext 不是很熟悉,所以如果有人有更好的方法来做到这一点,您的意见和建议将不胜感激。谢谢!

public static void main(String[] args) throws DocumentException, IOException{
    Document document = new Document(PageSize.A4, 50, 50, 70, 70);

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("C:/pdfwithfooter.pdf"));
        document.open();

        document.add(new Paragraph(
                "Hello Body of the PDF"));

        /** Format Font **/
        Font fontFooter = new Font(FontFactory.getFont(
                FontFactory.HELVETICA, 6));

        /**
         * Format Table Cell Borders
         */
        // cell.disableBorderSide(Rectangle.BOX);
        Rectangle page = document.getPageSize();
        PdfPTable foot = new PdfPTable(4);
        PdfPCell footCell = new PdfPCell(new Phrase(
                "OUR DOCUMENT'S LEGEND", FontFactory.getFont(
                        FontFactory.HELVETICA, 6, Font.BOLDITALIC)));
        footCell.setColspan(2);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase(""));
        footCell.setColspan(2);
        foot.addCell(footCell);

        // 1st row
        footCell = new PdfPCell(new Phrase("COX - COX", fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase("EQ - Equipment", fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase("OUT-XYZ - Out XXXXXXXXXXXXX",
                fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase(
                "ADJ-XX - Adjustment on XXXXXX XXXX", fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        // 2nd row
        footCell = new PdfPCell(new Phrase("EB - Electric Bills",
                fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase("T-BB - Transfer to Big Boat",
                fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase("T-XXXX - Transfer to XXXX",
                fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase("GX - Get XXXXXX", fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        // 3rd row
        footCell = new PdfPCell(new Phrase(
                "EXCEPTIONS - Invalid X Y VALUES", fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase("R XX - Removal of XX",
                fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase("T-X - Transfer of XXXX",
                fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase(
                "T-LX - Transfer of Leased XXXX", fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        // 4th row
        footCell = new PdfPCell(new Phrase("LX - Leased XXXX", fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase(
                "T-TX - Transfer to TREE XXXXXXX", fontFooter));
        footCell.setPaddingLeft(15);
        foot.addCell(footCell);
        footCell = new PdfPCell(new Phrase(
                "Adj-XXX - Adjustment Some Value",
                fontFooter));
        footCell.setPaddingLeft(15);
        footCell.setColspan(2);
        foot.addCell(footCell);

        foot.setTotalWidth(page.width() - document.leftMargin()
                - document.rightMargin());
        foot.writeSelectedRows(0, -1, document.leftMargin(),
                document.bottomMargin(), writer.getDirectContent());

        document.close();

}
于 2013-05-07T08:08:19.883 回答