作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想在使用 PDFBOX
创建的 PDF 中添加一个超链接,这样我单击某些文本示例“单击此处”将重定向到 URL。我尝试使用 PDAnnotationLink
和 PDActionURI
,但如何将其添加到 contentstream
中?
PDBorderStyleDictionary borderULine = new PDBorderStyleDictionary();
borderULine.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE);
PDAnnotationLink txtLink = new PDAnnotationLink();
txtLink.setBorderStyle(borderULine);
txtLink.setColour(colourBlue);
// add an action
PDActionURI action = new PDActionURI();
action.setURI("www.google.com");
txtLink.setAction(action);
contentStream.beginText();
contentStream.moveTextPositionByAmount(400, y-30);
contentStream.drawString(txtLink);----error
contentStream.endText();
最佳答案
要添加到 contentStream
使用以下代码
PDRectangle position = new PDRectangle();
position.setLowerLeftX(10);
position.setLowerLeftY(20);
position.setUpperRightX(100);
position.setUpperRightY(10);
txtLink.setRectangle(position);
page.getAnnotations().add(txtLink);
关于java - 如何使用pdfbox在pdf中添加超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21021502/
我是一名优秀的程序员,十分优秀!