Some test text!
Web / Guides / Introduction
By now, you should have setup WebViewer and read all about the DocumentViewer , but a very common use case is interacting with annotations.
The main way to access and work with annotations is through the AnnotationManager
. Like with the DocumentViewer when using the WebViewer UI, this is also available through the Core
namespace and is one of the main objects you will likely interact with.
Fetching a list of annotations in the document can be done via the AnnotationManager. This is done through the getAnnotationsList
API. This list is the complete list so it will include link annotations and widgets (form controls).
const { annotationManager, Annotations } = instance.Core;
annotationManager.getAnnotationsList().forEach(annot => {
if (annot instanceof Annotations.RectangleAnnotation) {
// Do something with annotation
}
});
If you know the ID of your annotation, you can use getAnnotationById
to get it.
const { annotationManager } = instance.Core;
const annot = annotationManager.getAnnotationById('fb049fb2-ec3e-4e7b-8e1a-243096e1924e');
If you are working with user interactions and would like to get the annotations under the cursor at some point, the AnnotationManager provides two methods that will help depending on what you want to do:
const { documentViewer, annotationManager } = instance.Core;
documentViewer.addEventListener('mouseLeftUp', (e) => {
const annotations = annotationManager.getAnnotationsByMouseEvent(e);
annotationManager.selectAnnotations(annotations);
});
Adding new annotations is also done through the AnnotationManager with the addAnnotation
or addAnnotations
API. Be sure to check out how to create annotations in our other guide.
const { annotationManager, Annotations } = instance.Core;
// Create an annotation using an object initializer
const rect = new Annotations.RectangleAnnotation({
X: 50,
Y: 50,
Width: 150,
Height: 50,
StrokeColor: new Annotations.Color(255, 0, 0, 1),
});
annotationManager.addAnnotation(rect);
// Always redraw annotation if rendering was updated
annotationManager.redrawAnnotation(rect);
Like with adding annotations, the AnnotationManager provides the deleteAnnotation
and deleteAnnotations
APIs to delete annotations. You must have a reference to the annotation to use these methods.
const { annotationManager } = instance.Core;
const annot = annotationManager.getAnnotationById('fb049fb2-ec3e-4e7b-8e1a-243096e1924e');
annotationManager.deleteAnnotation(annot);
Now that you know how to add annotations, learn how to create them!
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales