Java 将LinkAnnotation更改为SquareAnnotation(基于IcePDF中的给定示例)
由于从LinkAnnotation到SquareAnnotation的简单更改,我在使用icepdf时遇到了一个问题 特别是,我在icepdf网站上有一个例子: https://github.com/svn2github/icepdf/blob/master/examples/annotation/NewAnnotationPostPageLoad.java 还有一个有趣的部分(过滤评论和删除链接操作): 我要做的就是,将linkAnnotation更改为SquareAnnotation。因此,我将行更改为:Java 将LinkAnnotation更改为SquareAnnotation(基于IcePDF中的给定示例),java,pdf,icepdf,pdf-annotations,Java,Pdf,Icepdf,Pdf Annotations,由于从LinkAnnotation到SquareAnnotation的简单更改,我在使用icepdf时遇到了一个问题 特别是,我在icepdf网站上有一个例子: https://github.com/svn2github/icepdf/blob/master/examples/annotation/NewAnnotationPostPageLoad.java 还有一个有趣的部分(过滤评论和删除链接操作): 我要做的就是,将linkAnnotation更改为SquareAnnotation。因此,
AbstractPageViewComponent pageViewComponent = pageComponents.get(pageIndex);
for (WordText wordText: foundWords) {
// create a new link annotation
SquareAnnotation linkAnnotation = (SquareAnnotation) AnnotationFactory.buildAnnotation(
document.getPageTree().getLibrary(), Annotation.SUBTYPE_SQUARE,
wordText.getBounds().getBounds());
linkAnnotation.setColor(Color.red);
linkAnnotation.setFillColor(true);
linkAnnotation.setFillColor(new Color(1, 1, 0, 0.5f));
AnnotationComponent annotationComponent = AnnotationComponentFactory.buildAnnotationComponent(
linkAnnotation, controller.getDocumentViewController(),
pageViewComponent, controller.getDocumentViewController().getDocumentViewModel()
);
controller.getDocumentViewController().getAnnotationCallback().newAnnotation(
pageViewComponent, annotationComponent);
}
}
但是现在,注释在查看器中不再可见。我必须编辑注释并再次更改颜色,然后注释才是可见的
我的最终目标是实现一个小的无头程序来读取pdf,突出显示一些带有方形注释的单词,然后将该状态保存到图像中。到目前为止,它与示例中给出的标准LinkAnnotation一起工作,但似乎无法使SquareAnnotation正常工作。请查看org.icepdf.ri.common.tools.SquareAnnotationHandler()方法MouseRelease()将帮助您正确设置边界。我想你所缺少的就是 resetAppearanceStream(getPageTransform())
AbstractPageViewComponent pageViewComponent = pageComponents.get(pageIndex);
for (WordText wordText: foundWords) {
// create a new link annotation
SquareAnnotation linkAnnotation = (SquareAnnotation) AnnotationFactory.buildAnnotation(
document.getPageTree().getLibrary(), Annotation.SUBTYPE_SQUARE,
wordText.getBounds().getBounds());
linkAnnotation.setColor(Color.red);
linkAnnotation.setFillColor(true);
linkAnnotation.setFillColor(new Color(1, 1, 0, 0.5f));
AnnotationComponent annotationComponent = AnnotationComponentFactory.buildAnnotationComponent(
linkAnnotation, controller.getDocumentViewController(),
pageViewComponent, controller.getDocumentViewController().getDocumentViewModel()
);
controller.getDocumentViewController().getAnnotationCallback().newAnnotation(
pageViewComponent, annotationComponent);
}