Filtering annotation types

This feature can be using when need to save only specific annotation types and ignore others.

The following are the steps how to filter exported annotations to document: 

  • Instantiate Annotator object with input document path or stream;
  • Instantiate SaveOptions object and set AnnotationType desired annotation type(s), that will presented in resultant document;
  • Call save method with resultant document path or stream and SaveOptions object;

Following code snippet shows how to save only pages with specific annotation type

String outputPath = "FilteringAnnotationTypes.pdf";

Annotator annotator = new Annotator("input.pdf");

AreaAnnotation area = new AreaAnnotation();
area.setBox(new Rectangle(100, 100, 100, 100));
area.setBackgroundColor(65535);
area.setPageNumber(1);

EllipseAnnotation ellipse = new EllipseAnnotation();
ellipse.setBox(new Rectangle(100, 100, 100, 100));
ellipse.setBackgroundColor(123456);
ellipse.setPageNumber(4);

List<AnnotationBase> tmp0 = new ArrayList<AnnotationBase>();
tmp0.add(area);
tmp0.add(ellipse);
annotator.add(tmp0);

SaveOptions tmp1 = new SaveOptions();
tmp1.setAnnotationTypes(AnnotationType.Ellipse);

annotator.save(outputPath, tmp1);
annotator.dispose();

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 Java 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.