Extract annotations from document

GroupDocs.Annotation provides an ability to extract annotations from document and serializing to XML format.
To achieve this you should:

  • Instantiate Annotator object with input document path or stream;
  • Instantiate LoadOptions object and set ImportAnnotation = true;
  • Define variable with type List;
  • Call Get method and return result to variable above;
  • Instantiate XmlSerializer object with type List;
  • Using FileStreamobject, serialize annotations to the file as on example below;

The following code demonstrates how to extract annotation metadata from document:

// for using this example input file ("annotated.pdf") must be with annotations
using (Annotator annotator = new Annotator("annotated.pdf", new LoadOptions() { ImportAnnotations = true }))
{
	List<AnnotationBase> annotations = annotator.Get();
    XmlSerializer formatter = new XmlSerializer(typeof(List<AnnotationBase>));
    using (FileStream fs = new FileStream("annotations.xml", FileMode.Create))
    {
    	fs.SetLength(0);
        formatter.Serialize(fs, annotations);
    }
}

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.