【发布时间】:2018-05-03 03:25:27
【问题描述】:
在下面的代码中,我想在“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 时它应该重定向
【问题讨论】:
-
您还需要在此处添加链接注释。或者显示完整的 url,一些查看者在文本中搜索 URL 并将它们视为链接。
-
请在源代码下载中的AddAnnotations.java示例链接
-
哎呀,我的意思是在 AddAnnotations.java 示例中写“看”。
-
PDAnnotationLink txtLink = new PDAnnotationLink(); PDBorderStyleDictionary 下划线 = new PDBorderStyleDictionary(); underline.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE); txtLink.setBorderStyle(下划线); PDRectangle 位置 = 新 PDRectangle();位置.setLowerLeftX(325);位置.setLowerLeftY(210);位置.setUpperRightX(350);位置.setUpperRightY(220); txtLink.setRectangle(位置); PDActionURI 动作 = 新的 PDActionURI(); action.setURI("Google.com"); txtLink.setAction(action); page.getAnnotations().add(txtLink);
-
在下面添加代码并在链接不正确时使用它然后设置 PDRectanlge 对齐