如何使用 PDFBox 从 PDF 文档中删除链接

How to remove Links from a PDF Document using PDFBox

使用 PDFBox 从 PDF 中删除 link 的最佳方法是什么。示例:假设我将以下内容作为 PDF 的页面:

测试test1

我希望将其转换为

测试测试1

删除 link 但保留在本例中为 test1 的文本。

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://whosebug.com".equals(uri.getURI()))
            {
                annotations.remove(link);
                break;
            }                                
        }
    }
}
page.setAnnotations(annotations);