Remove annotation replies

There is a quick and convenient way to remove specific or even all replies for some document annotation using GroupDocs.Annotation API. It is as easy as removing items from generic List collection. In common case you have to follow these steps to delete replies:

  • Instantiate Annotator object with input document path or stream and with instantiated LoadOptions where ImportAnnotations property is set to true;
  • Call Get method of Annotator object and obtain collection of document annotations;
  • Access desired annotation object and remove reply in a most suitable way:
  • Call Update method of Annotator object and pass annotations collection into it;
  • Call Save method with resultant document path or stream;

Remove specific annotation reply 

The easiest way for removing specific annotation reply is to delete by its index inside Replies collection. The following code sample demonstrates how to remove first annotation reply:

// NOTE: Input document already contain annotations with replies
using (Annotator annotator = new Annotator("result.pdf", new LoadOptions { ImportAnnotations = true }))
{
    // Obtain annotations collection from document
    List<AnnotationBase> annotations = annotator.Get();               
	// Remove first reply 
	annotations[0].Replies.RemoveAt(0);
	// Save changes
	annotator.Update(annotations);
	annotator.Save("result.pdf");
}

Remove annotation replies by criteria

GroupDocs.Annotation API also provides a way to remove multiple annotation replies that match some criteria. The following code demonstrates how to remove replies that were added by user with name “Tom”:

// NOTE: Input document already contain annotations with replies
using (Annotator annotator = new Annotator("annotated_file_with_replies.pdf", new LoadOptions { ImportAnnotations = true }))
{
    // Obtain annotations collection from document
    List<AnnotationBase> annotations = annotator.Get();
    // Remove all replies where author name is "Tom"
    annotations[0].Replies.RemoveAll(x => x.User.Name == "Tom");
    // Save changes
    annotator.Update(annotations);
    annotator.Save("result.pdf");
}

More resources

Advanced Usage Topics

To learn more about document annotating features, please refer to the advanced usage section.

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to annotate your PDF, DOC or DOCX, XLS or XLSX, PPT or PPTX, PNG and other documents with free to use online GroupDocs Annotation App.