Add point annotation

On this page

Point annotation sticks comments to any point in a document as shown in the picture below:

You can use the following methods to set the properties of the PointAnnotation class:

  • setBox() defines the annotation position on the page

To add a point annotation, follow these steps:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the PointAnnotation class. Specify the appropriate properties (position, page number, etc).
  3. Call the add() method. Specify the PointAnnotation class.
  4. Call the save() method. Specify the output document path or stream. 

The following code snippet shows how to add PointAnnotation to the document:

// This example demonstrates adding point annotation.

// Create an instance of Annotator class
Annotator annotator = new Annotator("inputPath");
try {
    // Create an instance of Reply class and add comments
    Reply reply1 = new Reply();
    reply1.setComment("First comment");
    reply1.setRepliedOn(Calendar.getInstance().getTime());

    Reply reply2 = new Reply();
    reply2.setComment("Second comment");
    reply2.setRepliedOn(Calendar.getInstance().getTime());

    java.util.List<Reply> replies =  new ArrayList<Reply>();
    replies.add(reply1);
    replies.add(reply2);

    // Create an instance of PointAnnotation class and set options
    PointAnnotation point = new PointAnnotation();
    point.setBox(new Rectangle(100, 100, 0, 0));
    point.setCreatedOn(Calendar.getInstance().getTime());
    point.setMessage("This is point annotation");
    point.setPageNumber(0);
    point.setReplies(replies);
    
    // Add annotation and save to file
    annotator.add(point);
    annotator.save("outputPath");
} finally {
    if (annotator != null) {
        annotator.dispose();
    }
}

On this page