I am using Apache PDFBox version 2.0.x. I am trying to search a PDF using bookmarks and when I hit my target I should be able to get the Pagenumber the bookmark is referring to. This is my code to print all bookmarks. I can do an equals search like searchText.equals(current.getTitle())
public static void printBookmark(PDOutlineNode bookmark, String indentation) throws IOException {
PDOutlineItem current = bookmark.getFirstChild();
COSObject targetPageRef = null;
while (current != null) {
System.out.println(indentation + current.getTitle());
printBookmark(current, indentation + " ");
current = current.getNextSibling();
}
}
If the title matches my search text then that is my target bookmark. Anyone tried this before?