简体   繁体   English

PDF 注释/注释是否可以包含指向 PDF 中其他页面的链接?

[英]Can PDF notes/annotations include links to other pages in the PDF?

I want to add an annotation to a PDF page (ie something that would show as a pop-up note or appear in the list of notes for the current page).我想向 PDF 页面添加注释(即会显示为弹出式注释或出现在当前页面的注释列表中的内容)。

And in that note, I want to say " See page 93 ", where clicking on that takes the user to page 93.在那篇笔记中,我想说“见第 93 页”,点击它会将用户带到第 93 页。

Is that possible?那可能吗? It seems like a useful feature, but I haven't been able to find any examples.这似乎是一个有用的功能,但我找不到任何示例。

And if so, can it be done with Apache PDF Box?如果是这样,可以使用 Apache PDF Box 完成吗?

Yes (it is possible) and yes (it can be done with PdfBox).是(有可能)和是(可以用 PdfBox 完成)。 That question has been asked before and answered several times.这个问题以前有人问过,回答过好几次。 Read the follwing answer here and the see the full code here .阅读follwing答案在这里和看到完整的代码在这里

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

Other answers are here and here .其他答案在这里这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM