user1648409
user1648409

Reputation:

PDFBox - Getting Content height

How can i get the content height of a given page with pdfbox? I have X pages, where i need to add Y elements to. Once the first page is full, it should start a new page, putting out the rest of the Y elements and of course starting another page, once the second is also full.

So: How do i determine if the page is full - aka the content height?

I have something like this:

private static void addChapters() throws IOException {
    for(int i = 0; i < chapters.size(); i++) {

        // if page is full, add a new page and start printing on the new page here

        // Chapter Headline
        // some output here...

        // Data table
        // some more output here

        contentStream.close();
    }
}

Thanks!

Upvotes: 0

Views: 1095

Answers (1)

javi_swift
javi_swift

Reputation: 385

PdfBox doesn´t have the tools to control page layout. What I´ve done at first was to multiply the number of results I wanted in a single page and their size to obtain the total height I was about to use. Then you can start writting in an Y higher than this result and change to a new page when the fixed number is reached.

However, at the end I was trying to print results like in a table, so I used Boxable for Pdfbox(https://github.com/dhorions/boxable) which handles page switching for you.

Upvotes: 1

Related Questions