pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Retter <adam.ret...@googlemail.com>
Subject Problem with getting page size
Date Wed, 24 Aug 2016 14:31:20 GMT
I am using PDFBox 2.0.2 and trying to add a cover page to my PDF. The
Cover Page needs to have the same dimensions as the first page of the

I am trying to retrieve the size of the first page of the PDF using
the following code:

PDDocument doc = PDDocument.load(myFile);
PDPage originalFirstPage = doc.getPages().get(0);
float width = originalFirstPage.getMediaBox.getWidth();
float height = originalFirstPage.getMediaBox.getHeight();

However PDFBox is reporting the wrong size for a particular PDF file
that I have. It seems to be reporting the size as A4 when the pages in
PDF are not that size.

When I create a new cover page based on the code above and save the
new PDF, then I can visually see that the new cover page is much
bigger than the previous first page of the PDF. This is the code I

PDPage coverPage = new PDPage(new PDRectangle(width, height))
// add content to coverPage...
doc.getPages.insertBefore(coverPage, doc.getPage(0))

Can anyone tell me if this is a problem with the PDF, a bug in PDFBox
returning the wrong page size, or something daft that I am doing

The input PDF is available here for reference:

The output PDF (with my cover page) is here:

Thanks Adam

Adam Retter

skype: adam.retter
tweet: adamretter

To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org

View raw message