Kasper Helsted
Kasper Helsted

Reputation: 219

OpenPDF: Table not located in footer

When I add a table to the footer of the page, the footer resizes to the right size, however, the table does not stay within this footer, however it locates itself at the top of the page.

I have created a test scenario to illustrate what I mean.

public class TestClass {
    public static void main(String[] args) {
        try {
            Document document = new Document(PageSize.A4);

            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("fail.pdf"));

            PdfPTable table = new PdfPTable(2);
            table.setWidthPercentage(100);
            table.addCell(new PdfPCell(new Paragraph("CONTENT")));
            table.addCell(new PdfPCell(new Paragraph("CONTENT")));

            Paragraph footerParagraph = new Paragraph();
            footerParagraph.add(table);
            HeaderFooter footer = new HeaderFooter(footerParagraph, false);
            footer.setAlignment(Element.ALIGN_CENTER);

            document.setFooter(footer);

            document.open();

            document.add(new Paragraph("Hello World"));
            document.close();
        } catch (Exception ex) {
            System.out.println(ex);
        }
    }
}

In this example the the footer has the correct size for the table: Empty footer where the table should be

However as mentioned the table is not located at the bottom, but at the top: The table is located at the top of the page, on top of the other content

Upvotes: 3

Views: 964

Answers (2)

Kasper Helsted
Kasper Helsted

Reputation: 219

This was a bug with OpenPDF, which should have been fixed now. https://github.com/LibrePDF/OpenPDF/issues/373

Upvotes: 0

WARUTS
WARUTS

Reputation: 72

You need to know the page size and calculate from there.

You can use

showTextAligned(ELEMENT.ALIGN_BOTTOM)

Upvotes: 1

Related Questions