文档半岛外围网上直营>>Spire.PDF教程>>Spire.PDF功能演示:在 Java 中删除或更新 PDF 中的超链接
Spire.PDF功能演示:在 Java 中删除或更新 PDF 中的超链接
Spire.PDF for Java 是一款专门对 PDF 文档进行操作的 Java 类库。该类库的主要功能在于帮助开发人员在 Java 应用程序(J2SE和J2EE)中生成 PDF 文档和操作现有 PDF 文档,并且运行环境无需安装 Adobe Acrobat。
本文演示了如何使用 Spire.PDF for Java 删除或更新 PDF 文档中的超链接。当您使用本文所述的方法删除超链接时,超链接的外观将保持不变,但后面的链接将被删除。
可点击此处下载最新版测试。
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.annotations.PdfAnnotationCollection;
import com.spire.pdf.annotations.PdfUriAnnotationWidget;
public class RemoveHyperlinks {
public static void main(String[] args) throws Exception {
//Create a PdfDocument object
PdfDocument document = new PdfDocument();
//Load the sample PDF file
document.loadFromFile("C:\\Users\\Administrator\\Desktop\\Hyperlinks.pdf");
//Get the first page
PdfPageBase page = document.getPages().get(0);
//Get annotation collection
PdfAnnotationCollection widgetCollection = page.getAnnotationsWidget();
//Remove the second annotation which is a hyperlink in the document
widgetCollection.removeAt(1);
//Get the first url annotation widget
PdfUriAnnotationWidget uriWidget = (PdfUriAnnotationWidget)widgetCollection.get(0);
//Reset the url
uriWidget.setUri("//www.e-iceblue.com/Introduce/pdf-for-java.html");
//Save to file
document.saveToFile("Result.pdf");
}
}
输出结果
整合所有格式API处理套包Spire.office for Java正在慧都网火热销售中!立马1分钟了解全部咨询!

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线