当前位置: 代码迷 >> 综合 >> Spire.pdf.jar-pdf超链接查找替换
  详细解决方案

Spire.pdf.jar-pdf超链接查找替换

热度:67   发布时间:2023-12-18 02:22:18.0
Spire.Pdf.jar

Free Spire.PDF for Java | 100% 免费 Java PDF 组件

public static void linkReplace(String url) throws Exception {//加载PDF示例文档PdfDocument document = new PdfDocument();document.loadFromFile(url);//循环页码PdfPageCollection pages = document.getPages();for (Object page09 : pages) {PdfPageBase page= (PdfPageBase) page09;//获取所有的PDF 超链接集合PdfAnnotationCollection widgetCollection = page.getAnnotationsWidget();List<PdfUriAnnotationWidget> list = widgetCollection.getList();for (PdfUriAnnotationWidget uri : list) {String uri1 = uri.getUri();uri1= uri1.replace("https://oss-cn-beijing.aliyuncs.com/files", "https://oss-cn-qingdao.aliyuncs.com/files");uri.setUri(uri1);}}//保存文档document.saveToFile(url);}