Reputation: 183
I am newbie in Apache PDFbox. I want to extract all bookmarks in PDF file using PDFBox library in Java. Any idea how to extract them?
Upvotes: 3
Views: 6152
Reputation: 18861
From the PrintBookmarks example in the source code download
PDDocument document = PDDocument.load(new File("..."));
PDDocumentOutline outline = document.getDocumentCatalog().getDocumentOutline();
printBookmark(outline, "");
document.close();
(...)
public void printBookmark(PDOutlineNode bookmark, String indentation) throws IOException
{
PDOutlineItem current = bookmark.getFirstChild();
while (current != null)
{
System.out.println(indentation + current.getTitle());
printBookmark(current, indentation + " ");
current = current.getNextSibling();
}
}
Upvotes: 9