Add replies to annotation

On this page

GroupDocs.Annotation allows you to collaborate over document using annotations and annotation replies.

To update an annotation reply, follow these steps:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the User class.
  3. Instantiate the Reply class(es).
  4. Instantiate the annotation object of the appropriate type. Available annotation types are listed here.
  5. Assign the User class to Reply.User property (by default it is “Guest”).
  6. Assign the Reply class(es) to the Replies collection created at previous steps.
  7. Call the  add() method of the Annotator class. Specify the annotation.
  8. Call the save() method. Specify the output document path or stream.

The following code snippet shows how to add replies to annotation:

// This example demonstrates adding replies to annotation.

// Create an instance of Annotator class
Annotator annotator = new Annotator("inputPath");
try {
    // Create an instance of User class and add data
    User user1 = new User();
    user1.setId(1);
    user1.setName("Tom");
    user1.setEmail("somemail@mail.com");
    User user2 = new User();
    user2.setId(2);
    user2.setName("Jack");
    user2.setEmail("somebody@mail.com");
    User user3 = new User();
    user3.setId(3);
    user3.setName("Mike");
    user3.setEmail("somemike@mail.com");
    
    // Create an instance of AreaAnnotation class and set options
    AreaAnnotation area = new AreaAnnotation();
    area.setBackgroundColor(65535);
    area.setBox(new Rectangle(100, 100, 100, 100));
    area.setCreatedOn(Calendar.getInstance().getTime());
    area.setMessage("This is area annotation");
    area.setOpacity(0.7);
    area.setPageNumber(0);
    area.setPenColor(65535);
    area.setPenStyle(PenStyle.Dot);
    area.setPenWidth((byte) 3);

    // Create an instance of Reply class and add comments
    Reply reply1 = new Reply();
    reply1.setId(1);
    reply1.setComment("First comment");
    reply1.setRepliedOn(Calendar.getInstance().getTime());
    reply1.setUser(user1);

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

    Reply reply3 = new Reply();
    reply3.setId(3);
    reply3.setComment("Third comment");
    reply3.setRepliedOn(Calendar.getInstance().getTime());
    reply3.setUser(user1);

    Reply reply4 = new Reply();
    reply4.setId(4);
    reply4.setComment("Fourth comment");
    reply4.setRepliedOn(Calendar.getInstance().getTime());
    reply4.setUser(user2);
    
    Reply reply5 = new Reply();
    reply5.setId(5);
    reply5.setComment("Five comment");
    reply5.setRepliedOn(Calendar.getInstance().getTime());
    reply5.setUser(user3);

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

    area.setReplies(replies);
    
    // Add annotation and save to file
    annotator.add(area);
    annotator.save("outputPath");
} finally {
    if (annotator != null) {
        annotator.dispose();
    }
}

On this page