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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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();
}
}