Filtering annotations by type on saving document

On this page

To save only annotations of specific types, follow these steps:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the SaveOptions class. Set the AnnotationType property by specifying annotation type(s) to save.
  3. Call the Save method with the output document path or stream. Specify the SaveOptions class as a parameter.

The following code snippet shows how to save only pages with specific annotation type:

using (Annotator annotator = new Annotator(“input.pdf”)) { AreaAnnotation area = new AreaAnnotation() { Box = new Rectangle(100, 100, 100, 100), BackgroundColor = 65535, PageNumber = 1 }; EllipseAnnotation ellipse = new EllipseAnnotation() { Box = new Rectangle(100, 100, 100, 100), BackgroundColor = 123456, PageNumber = 1 }; annotator.Add(new List() { area, ellipse });

//Result file will contains only ellipse annotations.
annotator.Save("result.pdf" new SaveOptions { AnnotationTypes = AnnotationType.Ellipse});

}

If you need to save annotations of several types, use the OR operator ("|").

The following code snippet shows how to save pages with specific annotation types:

using (Annotator annotator = new Annotator("input.pdf"))
{
	...
    annotator.Save("result.pdf" new SaveOptions { AnnotationTypes = AnnotationType.Ellipse|AnnotationType.Watermark});
}

On this page