在下面的代码中,我想在“ 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时应该重定向
最佳答案
试试这个代码也可以
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);
关于java - 如何使用pdfbox设置内容中的超链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50146466/