Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将LinkAnnotation更改为SquareAnnotation(基于IcePDF中的给定示例)_Java_Pdf_Icepdf_Pdf Annotations - Fatal编程技术网

Java 将LinkAnnotation更改为SquareAnnotation(基于IcePDF中的给定示例)

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。因此,

由于从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);
}