Add distance annotation

On this page

Distance annotation shows a distance between objects in a document as shown in the picture below: 

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

To add a distance annotation to document, follow these steps:  

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

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

// This example demonstrates adding distance annotation.

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 DistanceAnnotation class and set options
    DistanceAnnotation distance = new DistanceAnnotation();
    distance.setBox(new Rectangle(200, 150, 200, 30));
    distance.setCreatedOn(Calendar.getInstance().getTime());
    distance.setMessage("This is distance annotation");
    distance.setOpacity(0.7);
    distance.setPageNumber(0);
    distance.setPenColor(65535);
    distance.setPenStyle(PenStyle.Dot);
    distance.setPenWidth((byte) 3);
    distance.setReplies(replies);
    
    // Add annotation and save to file
    annotator.add(distance);
    annotator.save("outputPath");
} finally {
    if (annotator != null) {
        annotator.dispose();
    }
}

On this page