java 使用aspose 处理pdf 超链接

mac2025-08-27  9

详情请参考文献aspose官方文档

 

Page page = document.getPages().getpage_item(1);

AnnotationCollection annos = page.getAnnotations(); Annotation an = annos.get_Item(1); Rectangle rect = an.Rect(); public static void insertHyperlink(Document doc, Page page, Rectangle rectangle, int destPageNum) { //调整角度 rectangle.rotate(page.getRotate()); LinkAnnotation link = new LinkAnnotation(page, rectangle); GoToAction action = null; if (destPageNum > 0 && destPageNum <= doc.getPages().size()) { action = new GoToAction(new XYZExplicitDestination(doc.getPages().get_Item(destPageNum), 0, doc.getPages().get_Item(destPageNum).getRect().getURY(), 0.0)); } else { action = new GoToAction(new XYZExplicitDestination(0, 0, 0, 0.0)); } link.setAction(action); link.setColor(com.aspose.pdf.Color.getWhite()); Border border = new Border(link); border.setWidth(0); link.setBorder(border); page.getAnnotations().add(link); }

//一下作为参考

List<TextFragment> tfs = new ArrayList<>(); TextFragmentAbsorber ta = new TextFragmentAbsorber(); TextSearchOptions op = new TextSearchOptions(rect); op.setLimitToPageBounds(true); ta.setTextSearchOptions(op); ta.visit(page); for (TextFragment tf : ta.getTextFragments()) { if (false == tf.getRectangle().isIntersect(rect)) { continue; } tfs.add(tf); } if (null != tfs) { for (TextFragment tf : tfs) { tf.getTextState().setForegroundColor(Color.getBlack()); } }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

最新回复(0)