Add Sticky Note Annotations in Java

Annotations are created using the AnnotationProvider.AddAnnotationJson method. To create an annotation on a page, use the annotation JSON format to add the annotation you want.

Creating Note Annotations

Note annotations are “sticky notes” attached to a point in a document. To create a note annotation, specify the text — and optionally, the icon and color.

Here’s an example of adding a note annotation with JSON:

	"bbox": [10, 10, 400, 400],
	"color": "#FFFF00",
	"icon": "comment",
	"opacity": 1,
	"pageIndex": 0,
	"pdfObjectId": 42,
	"text": "Read me! Important stuff.",
	"type": "pspdfkit/note",
	"v": 1

The JSON can be loaded from a file and added using addAnnotationJson:

String jsonString = Files.readAllBytes(Paths.get("path/to/my-annotation.json")).toString();
document.getAnnotationProvider().addAnnotationJson(new JSONObject(jsonString));