Anbringen von Annotationen via API
Anbringen von Annotationen via API
Beispielcode:
Anbringen von Annotationen
final Document document = getPageView().getDocument();
// Seitenindex (0-basierend)
final int pageIndex = 0;
// PageSegment mit Dokumentinhalt holen
final AbstractPageSegment ps = (AbstractPageSegment) document.getPage(pageIndex).getPageSegment(
DocumentLayer.DEFAULT);
// AnnotationPagesegment holen (wird neu erstellt, falls noch nicht vorhanden)
final AnnotationPageSegment aps = Annotations.getAnnotationPageSegment(document.getPage(pageIndex), true);
// Annotationsprofil laden (hier: Jadice-Annotationsformat)
final URL profileUrl = JadiceAnnotationReader.class.getResource("/default-annotation-profile.xml");
final AnnotationProfile annotationProfile = AnnotationProfile.load(profileUrl);
// Annotation anlegen
final RectangleAnnotation a = new RectangleAnnotation();
// Annotation einem Basistyp zuordnen (siehe default-annotation-profile.xml Datei)
a.setType(annotationProfile.getType("Rectangle"));
// Position
final float x = <x-Position in Pixel> * (Document.BASE_RESOLUTION / ps.getResolution().getX());
final float y = <y-Position in Pixel> * (Document.BASE_RESOLUTION / ps.getResolution().getX());
a.setLocation(x, y);
// Grösse
final float w = <Breite in Pixel> * (Document.BASE_RESOLUTION / ps.getResolution().getX());
final float h = <Höhe in Pixel> * (Document.BASE_RESOLUTION / ps.getResolution().getX());
a.setSize(w, h);
// Inhalt füllen
a.setFilled(true);
a.setFillColor(Color.WHITE);
// schwarzer Rand
a.setStrokeColor(Color.BLACK);
a.setLineWidth(1);
a.setLinePainted(true);
// Anno der Seite hinzufügen
aps.addAnnotation(a);
, multiple selections available, Use left or right arrow keys to navigate selected items