如何使用pdfbox在pdf中添加超链接
2022-09-03 02:09:02
我想在PDF中添加一个超链接,使用,这样我点击一些文本示例“点击这里”将重定向到URL。我尝试使用 和 ,但如何将其添加到?PDFBOX
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();