LinkAnnotation から SquareAnnotation への単純な変更により、icepdf の使用中に問題が発生しました。
特に、icepdf Web サイトからの例を次に示します。
https://github.com/svn2github/icepdf/blob/master/examples/annotation/NewAnnotationPostPageLoad.java
それで、興味深い部分があります(コメントをフィルタリングし、リンクアクションを削除しました):
.......
for (WordText wordText: foundWords) {
// create a new link annotation
LinkAnnotation linkAnnotation = (LinkAnnotation) AnnotationFactory.buildAnnotation(
document.getPageTree().getLibrary(), Annotation.SUBTYPE_LINK,
wordText.getBounds().getBounds());
BorderStyle borderStyle = new BorderStyle();
borderStyle.setBorderStyle(BorderStyle.BORDER_STYLE_SOLID);
borderStyle.setStrokeWidth(2.0f);
linkAnnotation.setBorderStyle(borderStyle);
linkAnnotation.setColor(Color.red);
AnnotationComponent annotationComponent = AnnotationComponentFactory.buildAnnotationComponent(
linkAnnotation, controller.getDocumentViewController(),
pageViewComponent, controller.getDocumentViewController().getDocumentViewModel()
);
controller.getDocumentViewController().getAnnotationCallback().newAnnotation(
pageViewComponent, annotationComponent);
}
....
私がしたいのは、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 を読み取り、正方形の注釈でいくつかの単語を強調表示し、その後その状態を IMAGE に保存するための小さなヘッドレス プログラムを実現することです。これまでのところ、例に示されている標準の LinkAnnotation で動作しますが、SquareAnnotation を動作させることはできないようです。