【问题标题】:How to get all bookmarks in PDF file using PDFBox in Java如何使用 Java 中的 PDFBox 获取 PDF 文件中的所有书签
【发布时间】:2016-02-07 23:21:47
【问题描述】:

我是 Apache PDFbox 的新手。我想使用 Java 中的 PDFBox 库提取 PDF 文件中的所有书签。知道如何提取它们吗?

【问题讨论】:

    标签: java pdf pdfbox


    【解决方案1】:

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

    【讨论】:

    • 我还必须得到页码。 PDPage currentPage = current.findDestinationPage(document) Integer pageNumber = document.documentCatalog.pages.indexOf(currentPage) + 1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多