Instantiate the Annotator class. Specify the input document path or stream.
Create an AnnotationBase implementation and specify Id of existed annotation (if annotation with that Id is not found, it is ignored) or path list of annotations (all existed annotations are removed).
Call the update method of the Annotator class. Specify annotations.
Call the save() method. Specify the output document path or stream.
The following code demonstrates how to update annotations:
// This example demonstrates how to update annotation.
// Create an instance of Annotator class
Annotatorannotator=newAnnotator("inputPath");try{// Create an instance of Reply class and add comments
Replyreply1=newReply();reply1.setComment("Original first comment");reply1.setRepliedOn(Calendar.getInstance().getTime());Replyreply2=newReply();reply2.setComment("Original second comment");reply2.setRepliedOn(Calendar.getInstance().getTime());java.util.List<Reply>replies=newArrayList<Reply>();replies.add(reply1);replies.add(reply2);// Create an instance of AreaAnnotation class and set options
AreaAnnotationoriginal=newAreaAnnotation();original.setId(1);original.setBackgroundColor(65535);original.setBox(newRectangle(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();}}LoadOptionstmp0=newLoadOptions();// Open annotated document
Annotatorannotator1=newAnnotator("outputPath",tmp0);try{// Create an instance of Reply class and add comments
Replyreply1=newReply();reply1.setComment("Updated first comment");reply1.setRepliedOn(Calendar.getInstance().getTime());Replyreply2=newReply();reply2.setComment("Updated second comment");reply2.setRepliedOn(Calendar.getInstance().getTime());java.util.List<Reply>replies=newArrayList<Reply>();replies.add(reply1);replies.add(reply2);// Suggest we want change some properties of existed annotation
AreaAnnotationupdated=newAreaAnnotation();updated.setId(1);updated.setBackgroundColor(255);updated.setBox(newRectangle(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();}}
You can also update annotation using Id or pass the list of annotations. In that case all previous annotations will be replaced by new list.
To do this, follow these steps:
Instantiate the Annotator class. Specify the input document path or stream.
Create an AnnotationBase implementation and set Id of existed annotation (if annotation with that Id is not found, it is ignored) or path list of annotations (all existed annotations will be removed).
Call the [update()]https://reference.groupdocs.com/annotation/java/com.groupdocs.annotation/annotator/#update-com.groupdocs.annotation.models.annotationmodels.AnnotationBase-) method of the Annotator class. Specify annotations.
Call the save() method. Specify the output document path or stream.
The following code demonstrates how to update annotations using Id:
using(Annotatorannotator=newAnnotator("input.pdf")){AreaAnnotationoriginal=newAreaAnnotation{Id=1,BackgroundColor=65535,Box=newRectangle(100,100,100,100),CreatedOn=DateTime.Now,Message="This is original annotation",Replies=newList<Reply>{newReply{Comment="Original first comment",RepliedOn=DateTime.Now},newReply{Comment="Original second comment",RepliedOn=DateTime.Now}}};// add original annotation
annotator.Add(original);annotator.Save("result.pdf");}// open annotated document
using(Annotatorannotator=newAnnotator("result.pdf")){//assuming we are going to change some properties of existing annotation
AreaAnnotationupdated=newAreaAnnotation{// It's important to set existed annotation Id
Id=1,BackgroundColor=255,Box=newRectangle(0,0,50,200),CreatedOn=DateTime.Now,Message="This is updated annotation",Replies=newList<Reply>{newReply{Comment="Updated first comment",RepliedOn=DateTime.Now},newReply{Comment="Updated second comment",RepliedOn=DateTime.Now}}};// update annotation
annotator.Update(updated);annotator.Save("result.pdf");}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.