Java 创建 link 使用 PDFBox 在 PDF 中分页
Java create link to page in PDF with PDFBox
我的程序link将 PDF 文件中的一个位置转换为同一文件中的另一页。因此,您可以单击文件中定义的位置,然后您将 linked 到另一页。
我用一个PDRectangle
来定义位置。不幸的是,矩形在文档中是可见的。我想创建没有可见边框的 link。
我的代码:
PDActionGoTo action = new PDActionGoTo();
action.setDestination(destination);
PDAnnotationLink annotationLink = new PDAnnotationLink();
annotationLink.setAction(action);
PDRectangle position = new PDRectangle();
position.setLowerLeftX(bookmarkLinkPositionEntry.getLowerLeftX());
position.setLowerLeftY(bookmarkLinkPositionEntry.getLowerLeftY());
position.setUpperRightX(bookmarkLinkPositionEntry.getUpperRightX());
position.setUpperRightY(bookmarkLinkPositionEntry.getUpperRightY());
annotationLink.setRectangle(position);
destinationPDF.getPage(0).getAnnotations().add(annotationLink);
我尝试使用 annotationLink.setHidden(true);
和 annotationLink.setNoView(true);
。文档只说 "Set the hidden flag." 和 "Set the noView flag." 我不知道那里到底发生了什么。
如何更改矩形的可见性或完全删除边框?
您需要设置边框样式:
PDBorderStyleDictionary borderULine = new PDBorderStyleDictionary();
borderULine.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE);
borderULine.setWidth(0);
annotationLink.setBorderStyle(borderULine);
有关此主题的更多信息,请参见源代码下载 AddAnnotations.java example。
我的程序link将 PDF 文件中的一个位置转换为同一文件中的另一页。因此,您可以单击文件中定义的位置,然后您将 linked 到另一页。
我用一个PDRectangle
来定义位置。不幸的是,矩形在文档中是可见的。我想创建没有可见边框的 link。
我的代码:
PDActionGoTo action = new PDActionGoTo();
action.setDestination(destination);
PDAnnotationLink annotationLink = new PDAnnotationLink();
annotationLink.setAction(action);
PDRectangle position = new PDRectangle();
position.setLowerLeftX(bookmarkLinkPositionEntry.getLowerLeftX());
position.setLowerLeftY(bookmarkLinkPositionEntry.getLowerLeftY());
position.setUpperRightX(bookmarkLinkPositionEntry.getUpperRightX());
position.setUpperRightY(bookmarkLinkPositionEntry.getUpperRightY());
annotationLink.setRectangle(position);
destinationPDF.getPage(0).getAnnotations().add(annotationLink);
我尝试使用 annotationLink.setHidden(true);
和 annotationLink.setNoView(true);
。文档只说 "Set the hidden flag." 和 "Set the noView flag." 我不知道那里到底发生了什么。
如何更改矩形的可见性或完全删除边框?
您需要设置边框样式:
PDBorderStyleDictionary borderULine = new PDBorderStyleDictionary();
borderULine.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE);
borderULine.setWidth(0);
annotationLink.setBorderStyle(borderULine);
有关此主题的更多信息,请参见源代码下载 AddAnnotations.java example。