i have a problem while using icepdf due a simple change from LinkAnnotation to SquareAnnotation.
In special i have this example from the icepdf website:
https://github.com/svn2github/icepdf/blob/master/examples/annotation/NewAnnotationPostPageLoad.java
so and there is the interesting part (filtered the comments and removed link-action) :
.......
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);
}
....
all i want to do is, to change the linkAnnotation to an SquareAnnotation. so i changed the lines to this:
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);
}
}
But now, the annotation is not visible in the viewer anymore. I have to edit the annotation and change the color again, after that, the annotation is visible correct.
My final goal is to achieve a small headless program to read a pdf, highlight some words with the square annotation and after that save that state to an IMAGE. it works so far with the standard LinkAnnotation which is given in the example but it seems not possible to get the SquareAnnotation to work.