Extract annotations from document

On this page

GroupDocs.Annotation allows you to extract annotations from a document and serialize them to the XML format.

To do this, follow these steps:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the LoadOptions class and set ImportAnnotation = true.
  3. Define a variable of the List<AnnotationBase> type.
  4. Call the Get method to get result to variable defined on the previous step.
  5. Instantiate the XmlSerializer class with the List<AnnotationBase> type.
  6. Using FileStreamobject, serialize annotations to the file.

The following code snippet shows how to extract annotations from a document:

// for using this example input file ("annotated.pdf") must have annotations
using (Annotator annotator = new Annotator("annotated.pdf"))
{
	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);
    }
}

On this page