Update annotation replies

On this page

GroupDocs.Annotation allows you to update annotation replies by accessing them using the Replies collection.

To update annotation replies, follow these steps:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Call the get() method of the Annotator class to get collection of the document annotations.
  3. Access desired reply object via getReplies() method collection by its index (zero-based) and update its properties as needed.
  4. Call the update method of the Annotator class. Specify annotations.
  5. Call the save() method. Specify the output document path or stream and the SaveOptions class.

The following code snippet shows how to update reply by index: 

// This example demonstrates how to update 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("Original first comment");
    reply1.setRepliedOn(Calendar.getInstance().getTime());

    Reply reply2 = new Reply();
    reply2.setComment("Original 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 AreaAnnotation class and set options
    AreaAnnotation original = new AreaAnnotation();
    original.setId(1);
    original.setBackgroundColor(65535);
    original.setBox(new Rectangle(100, 100, 100, 100));
    original.setCreatedOn(Calendar.getInstance().getTime());
    original.setMessage("This is original annotation");
    original.setReplies(replies);
    
    // Add original annotation
    annotator.add(original);
    
    // Save to file
    annotator.save("outputPath");
} finally {
    if (annotator != null) {
        annotator.dispose();
    }
}
LoadOptions tmp0 = new LoadOptions();

// Open annotated document
Annotator annotator1 = new Annotator("outputPath", tmp0);
try {
    // Create an instance of Reply class and add comments
    Reply reply1 = new Reply();
    reply1.setComment("Updated first comment");
    reply1.setRepliedOn(Calendar.getInstance().getTime());

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

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

    // Suggest we want change some properties of existed annotation
    AreaAnnotation updated = new AreaAnnotation();
    updated.setId(1);
    updated.setBackgroundColor(255);
    updated.setBox(new Rectangle(0, 0, 50, 200));
    updated.setCreatedOn(Calendar.getInstance().getTime());
    updated.setMessage("This is updated annotation");
    updated.setReplies(replies);
    
    // update annotation
    annotator1.update(updated);
    
    // Save to file
    annotator1.save(outputPath);
} finally {
    if (annotator1 != null) {
        annotator1.dispose();
    }
}

On this page