PDF annotations are essential for modern document workflows. Whether you’re reviewing contracts, collaborating on technical documents, marking up reports, or collecting feedback, annotations allow users to add comments and visual markups without modifying the original PDF content.
With Apryse WebViewer, developers can create, manage, and customize PDF annotations through both an intuitive user interface and a powerful JavaScript API.
WebViewer supports a wide range of annotation types, including:
| Category | Annotation Types |
|---|---|
| Comments | Sticky Notes, Comments |
| Text Markup | Highlight, Underline, Squiggly, Strikeout |
| Shapes | Rectangle, Ellipse, Polygon, Polyline, Line, Arrow |
| Drawing | Ink, Cloud |
| Text | FreeText, Callout |
| Review | Stamp, Redaction |
| Security | Signatures |
| Attachments | Files, Sound, Movie, 3D |
| Custom | Developer-defined annotation types |
The AnnotationManager is the primary API used to work with annotations programmatically in WebViewer.
Once WebViewer is initialized, it becomes available through the Core namespace:
const { annotationManager } = instance.Core;
The AnnotationManager allows developers to:
To retrieve all annotations in a document, use the getAnnotationsList() method.
const { annotationManager, Annotations } = instance.Core;annotationManager.getAnnotationsList().forEach(annot => {if (annot instanceof Annotations.RectangleAnnotation) {console.log('Rectangle annotation found');}});
This method returns all annotations, including:
If you already know an annotation’s unique identifier, you can retrieve it directly.
const { annotationManager } = instance.Core;const annot = annotationManager.getAnnotationById('fb049fb2-ec3e-4e7b-8e1a-243096e1924e');
This is useful when managing annotations stored in databases or collaborative review systems.
For interactive applications, you may need to identify which annotation a user clicked.
WebViewer provides:
getAnnotationByMouseEvent()getAnnotationsByMouseEvent()Example:
const { documentViewer, annotationManager } = instance.Core;documentViewer.addEventListener('mouseLeftUp', (e) => {const annotations =annotationManager.getAnnotationsByMouseEvent(e);annotationManager.selectAnnotations(annotations);});
This enables custom annotation selection workflows and contextual menus.
Although users typically create annotations through the WebViewer UI, developers can generate them programmatically.
const { annotationManager, Annotations } = instance.Core;const rect = new Annotations.RectangleAnnotation({X: 50,Y: 50,Width: 150,Height: 50,StrokeColor: new Annotations.Color(255, 0, 0, 1),});annotationManager.addAnnotation(rect);annotationManager.redrawAnnotation(rect);
Whenever you add an annotation or modify its properties directly, call:
annotationManager.redrawAnnotation(annotation);
This ensures the annotation is rendered correctly in the viewer.