java 使用aspose 处理pdf 超链接

详情请参考文献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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值