Create Markup 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 Markup Annotations

A markup annotation can be a highlight, underline, strikeout, or squiggle.

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

	"bbox": [10, 10, 400, 400],
	"color": "#00FF00",
	"opacity": 1,
	"pageIndex": 0,
	"rects": [[10, 10, 400, 400]],
	"type": "pspdfkit/markup/highlight",
	"v": 1

To alter the markup type, change the "type" key value to one of the following:

  • pspdfkit/markup/highlight

  • pspdfkit/markup/squiggly

  • pspdfkit/markup/strikeout

  • pspdfkit/markup/underline

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));