PDF pages (like almost anything else in arrays or lists) are 0-based. That means that 0 refers to the first item, 1 to the second one, etc. So PDF page #2 refers to the third physical page in the document. Acrobat is a user-facing application so it uses the more conventional 1-based way of referring to the these items, so the first page in a document is #1, the second page is #2, etc. This is something you always have to keep in mind when switching between a development environment and a user environment.
On Mon, May 4, 2015 at 1:26 PM, Johanneke Lamberink < [email protected]> wrote: > Hi, > > In my project I am exporting bookmarks from a PDF to an XML file, and at > another stage importing the bookmarks from the XML file into the PDF. In > doing this I've noticed an issue with the index of the page returned by the > PDPageDestination methods. > > My situation is as follows: > I have a PDF with a bookmark on the second page. That bookmark is > represented by a PDOutlineItem with a PDActionGoTo and a PDPageDestination. > Calling PDPageDestination.findPageNumber() on the bookmark's destination > results in the integer 2. So far so good. I write to my XML file that the > bookmark is on page 2. > When reading the XML, I create a new PDGoTo action with a > PDPageDestination. This PDPageDestination receives an array with the > integer 2 as the first element. > When I ask this new PDPageDestination for its pagenumber, using > PDPageDestination.findPageNumber(), I receive 2. Since this is the same > code I used to determine the bookmarked page in the first place, I would > expect the bookmark to be made for the correct page at this point. > > However, when I open the PDF in Adobe Acrobat Pro and inspect the > bookmark, it says the page destination is 3! When going to the bookmark > destination, I end up on the third page of the PDF. > > Is this a bug in PDFBox? And does anyone have a solution on how to fix > this? > > Kind regards, > > > Johanneke Lamberink >

