How to get all bookmarks in PDF file using PDFBox in Java

情到浓时终转凉″ 提交于 2019-12-23 22:24:00

问题


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();
    }
}


来源:https://stackoverflow.com/questions/35260456/how-to-get-all-bookmarks-in-pdf-file-using-pdfbox-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!