Thank you, that was exactly the issue. All working now :-) On 24 August 2016 at 18:23, Tilman Hausherr <thaush...@t-online.de> wrote: > Your page has also a cropbox. You need to set that as well. Alternatively, > just take the widths of the cropbox and use them for the new mediabox. > > Tilman > > > Am 24.08.2016 um 16:31 schrieb Adam Retter: >> >> 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 >> PDF. >> >> 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 >> use: >> >> 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 >> wrong? >> >> The input PDF is available here for reference: >> https://dl.dropboxusercontent.com/u/35135948/S0017383512000046a.pdf >> >> The output PDF (with my cover page) is here: >> https://dl.dropboxusercontent.com/u/35135948/out.pdf >> >> >> Thanks Adam >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org > For additional commands, e-mail: users-h...@pdfbox.apache.org >
-- Adam Retter skype: adam.retter tweet: adamretter http://www.adamretter.org.uk --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org For additional commands, e-mail: users-h...@pdfbox.apache.org