【问题标题】:Can PDF notes/annotations include links to other pages in the PDF?PDF 注释/注释是否可以包含指向 PDF 中其他页面的链接?
【发布时间】:2021-12-24 14:17:25
【问题描述】:

我想为 PDF 页面添加注释(即显示为弹出式注释或出现在当前页面注释列表中的注释)。

在那条注释中,我想说“See page 93”,点击它会将用户带到第 93 页。

这可能吗?这似乎是一个有用的功能,但我找不到任何示例。

如果是这样,可以用 Apache PDF Box 完成吗?

【问题讨论】:

    标签: pdf hyperlink annotations pdfbox


    【解决方案1】:

    是的(有可能)和是的(可以用 PdfBox 完成)。这个问题之前已经被问过并回答了好几次。阅读以下答案here 并查看完整代码here

    try (   InputStream resource = getClass().getResourceAsStream("some.pdf")) {
                PDDocument document = Loader.loadPDF(resource);
    
                PDPage page = document.getPage(1);
    
                PDAnnotationLink link         = new PDAnnotationLink();
                PDPageDestination destination = new PDPageFitWidthDestination();
                PDActionGoTo action           = new PDActionGoTo();
    
                //destination.setPageNumber(2);
                destination.setPage(document.getPage(2));
                action.setDestination(destination);
                link.setAction(action);
                link.setPage(page);
    
                link.setRectangle(page.getMediaBox());
                page.getAnnotations().add(link);
    
                document.save(new File("RESULT_FOLDER", "output-with-link.pdf"));
            }
    

    其他答案是herehere

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-15
      • 1970-01-01
      • 2019-11-08
      • 1970-01-01
      • 2012-11-24
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多