PDPageTree implements COSObjectable, Iterable<PDPage> { public int indexOf(PDPage page) { SearchContext context = new SearchContext(page); if (findPage(context, root)) { return context.index; } return -1; } PDPageTree();  PDPageTree(COSDictionary root);   PDPageTree(COSDictionary root, PDDocument document); static COSBase getInheritableAttribute(COSDictionary node, COSName key); @Override Iterator<PDPage> iterator(); PDPage get(int index); int indexOf(PDPage page); int getCount(); @Override COSDictionary getCOSObject(); void remove(int index); void remove(PDPage page); void add(PDPage page);  }
@Test public void indexOfPageFromOutlineDestination() throws IOException { doc = PDDocument.load(TestPDPageTree.class.getResourceAsStream("/pdfbox/com/tom_roush/pdfbox/pdmodel/with_outline.pdf")); PDDocumentOutline outline = doc.getDocumentCatalog().getDocumentOutline(); for (PDOutlineItem current : outline.children()) { if (current.getTitle().contains("Second")) { assertEquals(2, doc.getPages().indexOf(current.findDestinationPage(doc))); } } }
@Test public void positiveSingleLevel() throws IOException { doc = PDDocument.load(TestPDPageTree.class.getResourceAsStream("/pdfbox/com/tom_roush/pdfbox/pdmodel/with_outline.pdf")); for (int i = 0; i < doc.getNumberOfPages(); i++) { assertEquals(i, doc.getPages().indexOf(doc.getPage(i))); } }
@Test public void positiveMultipleLevel() throws IOException { doc = PDDocument.load(TestPDPageTree.class.getResourceAsStream("/pdfbox/com/tom_roush/pdfbox/pdmodel/page_tree_multiple_levels.pdf")); for (int i = 0; i < doc.getNumberOfPages(); i++) { assertEquals(i, doc.getPages().indexOf(doc.getPage(i))); } }
@Test public void negative() throws IOException { doc = PDDocument.load(TestPDPageTree.class.getResourceAsStream("/pdfbox/com/tom_roush/pdfbox/pdmodel/with_outline.pdf")); assertEquals(-1, doc.getPages().indexOf(new PDPage())); }