Spire.PDF for Java 是一款专门对 PDF 文档进行操作的 Java 类库。该类库的主要功能在于帮助开发人员在 Java 应用程序(J2SE和J2EE)中生成 PDF 文档和操作现有 PDF 文档,并且运行环境无需安装 Adobe Acrobat。
可点击此处下载最新版测试。
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("https://www.e-iceblue.com/Introduce/pdf-for-java.html"); //Save to file document.saveToFile("Result.pdf"); }}
输出结果

整合所有格式API处理套包Spire.office for Java正在 火热销售中!联系客服立马1分钟了解全部咨询!
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!