Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-2704

PDPageTree.indexOf doesn't find page numbers


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.0
    • Component/s: PDModel
    • Labels:
    • Environment:
      2.0.0-SNAPSHOT r1665633


      I know PDFBOX-2423 is not closed yet so I'm not sure if the issues I'm having are a cause of that.
      I'm using the latest trunk and I have issues with the PDPageTree.indexOf method. The javadoc reads Returns the index of the given page, or -1 if it does not exist. which I understand it means in returns -1 if the given page is not found in the page tree correct? If so, the following unit test fails:

          public void indexOfNotFoundPage() throws IOException {
              PDDocument doc1 = PDDocument.load(getClass().getClassLoader()
              assertEquals(-1, doc1.getPages().indexOf(new PDPage()));

      Another similar issue I have is that PDPageTree.indexOf doesn't find the correct index for a PDPage returned by the PDOutlineItem.findDestinationPage:

          public void indexOfPageFromOutlineDestination() throws IOException {
              PDDocument doc = PDDocument
              PDDocumentOutline outline = doc.getDocumentCatalog().getDocumentOutline();
              for (PDOutlineItem current : outline.children()) {
                  if (current.getTitle().contains("Second")) {
                      assertEquals(3, doc.getPages().indexOf(current.findDestinationPage(doc)));

      Also note that indexOf is used by PDPageDestination.findPageNumber which also returns a wrong result.


        1. bigger_outline_test.pdf
          20 kB
          Andrea Vacondio
        2. page_tree_index_of.diff
          7 kB
          Andrea Vacondio
        3. page_tree_multiple_levels.pdf
          2 kB
          Andrea Vacondio
        4. with_outline.pdf
          20 kB
          Andrea Vacondio

          Issue Links



              • Assignee:
                tilman Tilman Hausherr
                torakiki Andrea Vacondio
              • Votes:
                2 Vote for this issue
                4 Start watching this issue


                • Created: