【问题标题】:How to remove Links from a PDF Document using PDFBox如何使用 PDFBox 从 PDF 文档中删除链接
【发布时间】:2021-02-21 23:42:55
【问题描述】:

使用 PDFBox 从 PDF 中删除链接的最佳方法是什么。示例:假设我在 PDF 中有以下页面:

测试test1

我希望将其转换为

测试测试1

删除链接,但在这种情况下保留 test1 的文本。

【问题讨论】:

    标签: java pdf hyperlink pdfbox


    【解决方案1】:
    List<PDAnnotation> annotations = page.getAnnotations();
    for (PDAnnotation annotation : annotations)
    {
        PDAnnotation annot = annotation;
        if (annot instanceof PDAnnotationLink)
        {
            PDAnnotationLink link = (PDAnnotationLink) annot;
            PDAction action = link.getAction();
            if (action instanceof PDActionURI)
            {
                PDActionURI uri = (PDActionURI) action;
                if ("https://stackoverflow.com".equals(uri.getURI()))
                {
                    annotations.remove(link);
                    break;
                }                                
            }
        }
    }
    page.setAnnotations(annotations);
    

    【讨论】:

    • 非常感谢@tilman 的回复。这对我有用!
    • 很高兴听到这个消息,请点击复选标记图标使其成为接受的答案。
    猜你喜欢
    • 2011-08-17
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    • 2010-11-08
    • 2014-01-28
    相关资源
    最近更新 更多