如何使用pdfbox在内容中设置超链接 [英] how to set hyperlink in content using pdfbox
本文介绍了如何使用pdfbox在内容中设置超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码中,我想在Google.com"中添加超链接
In Below code i want to add hyperlink in "Google.com"
contentStream.beginText();
contentStream.setNonStrokingColor(0,0,0);
contentStream.setFont(PDType1Font.TIMES_ROMAN, 8);
contentStream.newLineAtOffset(315, 220);
contentStream.showText("Website: google.com");
contentStream.endText();
我想在 google.com 中显示超链接,它应该在点击 google.com 时重定向
I want to display hyperlink in google.com and it should redirect when clicking on google.com
推荐答案
试试这个代码也行,
contentStream.beginText();
contentStream.setNonStrokingColor(0,0,0);
contentStream.setFont(PDType1Font.TIMES_ROMAN, 8);
contentStream.newLineAtOffset(50,220);
contentStream.showText("Website: google.com");
contentStream.endText();
// create a link annotation
PDAnnotationLink txtLink = new PDAnnotationLink();
// add an underline
PDBorderStyleDictionary underline = new PDBorderStyleDictionary();
underline.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE);
txtLink.setBorderStyle(underline);
PDRectangle position = new PDRectangle();
position.setLowerLeftX(75);
position.setLowerLeftY(210);
position.setUpperRightX(85);
position.setUpperRightY(220);
txtLink.setRectangle(position);
PDActionURI action = new PDActionURI();
action.setURI("http://www.Google.com");
txtLink.setAction(action);
page.getAnnotations().add(txtLink);
这篇关于如何使用pdfbox在内容中设置超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文