我是Apache PDFbox的新手。我想用Java中的PDFBox库提取PDF文件中的所有书签。知道如何提取它们吗?
答案 0 :(得分:6)
来自源代码下载中的PrintBookmarks example
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();
}
}