OpenPDF icon indicating copy to clipboard operation
OpenPDF copied to clipboard

Table in footer get wrong y value

Open KasperHelsted opened this issue 6 years ago • 9 comments

When i try and add a table to the footer of a page, I would expect the table to be within the marked lines at the bottom of the page, however this is not the result.

The table is located at the top of the page, and not at the desired position, this is the same if the table is added to the header, the table is placed just after the margin.

I have created a test scenario to show 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);
        }
    }
}

I have tried to diagnose the problem, but all I was able to find was that when the "writeSelectedRows" method was called, the y position was 806, which was at the top of the page.

KasperHelsted avatar May 23 '20 14:05 KasperHelsted

After further digging, I can see it's the same for Image and SimpleTable

KasperHelsted avatar May 23 '20 18:05 KasperHelsted

Is there any workaround for this?

nikolavojicic avatar Mar 28 '21 02:03 nikolavojicic

I am interested in working on this issue. Is there a contributor guide somewhere?

mrcstan avatar Oct 19 '21 05:10 mrcstan

Just create a PR! Take a look at https://github.com/LibrePDF/OpenPDF/wiki/Coding-Convention .

asturio avatar Oct 19 '21 06:10 asturio

I'll be introducing a PR for this this week. Thanks

cesiabulnes avatar Dec 02 '21 05:12 cesiabulnes

It seems that the PR above isn't accepted, I will try this issue.

ObsisMc avatar Mar 18 '22 07:03 ObsisMc

Any progress on that, because I need it too.

mars3142 avatar Jun 09 '22 15:06 mars3142

The closing issue https://github.com/LibrePDF/OpenPDF/pull/697 only seems to handle images, or am I missing something? The initial report about tables is still not working. Can someone chime in and try it out to ensure it's not a problem on my end?

Otherwise I'll give it a try next week.

bcersows avatar Sep 23 '22 10:09 bcersows

The closing issue #697 only seems to handle images, or am I missing something? The initial report about tables is still not working. Can someone chime in and try it out to ensure it's not a problem on my end?

Otherwise I'll give it a try next week.

It indeed only handles images.

ObsisMc avatar Sep 23 '22 15:09 ObsisMc