Determine annotation types in Apryse WebViewer

There are a number of WebViewer annotation types, including cloud, polygon, free hand, and stamp, among others.

To determine annotation types, programmatically, you may need to review a mix of annotation properties. Most can be distinguished using instanceof to check its object type, but, for those that share the same type, like cloud and polygon which both use the type polygon, you'll need to go one step further and review additional properties.

The following is a list of annotation object types and their properties:

TypeProperties
Arcannotation instanceof window.Core.Annotations.ArcAnnotation
Arc measurementannotation instanceof window.Core.Annotations.ArcAnnotation && annotation.IT === 'ArcDimension'
Areaannotation instanceof window.Core.Annotations.PolygonAnnotation && annotation.IT === "PolygonDimension"
Area measurementannotation instanceof window.Core.Annotations.PolygonAnnotation && annotation.IT === 'PolygonDimension' && annotation.Measure
Arrowannotation instanceof window.Core.Annotations.LineAnnotation && annotation.IT === 'LineArrow'
Calloutannotation instanceof window.Core.Annotations.FreeTextAnnotation && annotation.getIntent() === window.Core.Annotations.FreeTextAnnotation.Intent.FreeTextCallout
Change viewannotation instanceof window.Core.Annotations.StampAnnotation && annotation.ViewState
Check box form fieldannotation instanceof window.Core.Annotations.CheckButtonWidgetAnnotation
Cloudannotation instanceof window.Core.Annotations.PolygonAnnotation && annotation.Style === 'cloudy'
Cloudy rectangular area measurementannotation instanceof window.Core.Annotations.PolygonAnnotation && annotation.IT === 'PolygonDimension' && annotation.Measure && annotation.isRectangularPolygon() && annotation.Style === 'cloudy'
Combo box form fieldannotation instanceof window.Core.Annotations.ChoiceWidgetAnnotation
Count measurementannotation instanceof window.Core.Annotations.StickyAnnotation && annotation.getCustomData('trn-is-count')
Date free textannotation instanceof window.Core.Annotations.FreeTextAnnotation && ToolName === 'AnnotationCreateDateFreeText'
Distance measurementannotation instanceof window.Core.Annotations.LineAnnotation && annotation.IT === 'LineDimension' && annotation.Measure
Dotannotation instanceof window.Core.Annotations.StampAnnotation && annotation.stampText === "Dot"
Ellipseannotation instanceof window.Core.Annotations.EllipseAnnotation
Ellipse areaannotation instanceof window.Core.Annotations.EllipseAnnotation && annotation.IT === 'EllipseDimension'
Ellipse measurementannotation instanceof window.Core.Annotations.EllipseAnnotation && annotation.IT === 'EllipseDimension' && annotation.Measure
Free handannotation instanceof window.Core.Annotations.FreeHandAnnotation && annotation.ToolName === "AnnotationCreateFreeHand"
Free hand highlightannotation instanceof window.Core.Annotations.FreeHandAnnotation && annotation.ToolName === "AnnotationCreateFreeHandHighlight"
File attachmentannotation instanceof window.Core.Annotations.FileAttachmentAnnotation
Free textannotation instanceof window.Core.Annotations.FreeTextAnnotation
Highlight annotation instanceof window.Core.Annotations.TextHighlightAnnotation && annotation.getCustomData('officeEditorTrackedChangeUID') === ''
Imageannotation instanceof window.Core.Annotations.StampAnnotation && annotation.ToolName === 'AnnotationCreateStamp'
Lineannotation instanceof window.Core.Annotations.LineAnnotation && annotation.IT !== 'LineArrow'
List box form fieldannotation instanceof window.Core.Annotations.ListWidgetAnnotation
Mark insert textannotation instanceof window.Core.Annotations.CaretAnnotation
Mark replace textannotation instanceof window.Core.Annotations.CaretAnnotation && annotation.IT === 'Replace'
Perimeter measurementannotation instanceof window.Core.Annotations.PolylineAnnotation && annotation.IT === 'PolyLineDimension' && annotation.Measure
Polygonannotation instanceof window.Core.Annotations.PolygonAnnotation && annotation.Style !== 'cloudy'
Polylineannotation instanceof window.Core.Annotations.PolylineAnnotation
Push button form fieldannotation instanceof window.Core.Annotations.PushButtonWidgetAnnotation
Radio button form fieldannotation instanceof window.Core.Annotations.RadioButtonWidgetAnnotation
Rectangleannotation instanceof window.Core.Annotations.RectangleAnnotation
Rectangular area measurementannotation instanceof window.Core.Annotations.PolygonAnnotation && annotation.IT === 'PolygonDimension' && annotation.Measure && annotation.isRectangularPolygon()
Redactionannotation instanceof window.Core.Annotations.RedactionAnnotation
Signatureannotation instanceof window.Core.Annotations.SignatureWidgetAnnotation && annotation.Subject === 'Widget'
Signature form fieldannotation instanceof window.Core.Annotations.SignatureWidgetAnnotation
Soundannotation instanceof window.Core.Annotations.SoundAnnotation
Squigglyannotation instanceof window.Core.Annotations.TextSquigglyAnnotation
Stampannotation instanceof window.Core.Annotations.StampAnnotation
Sticky noteannotation instanceof window.Core.Annotations.StickyAnnotation
Strikeoutannotation instanceof window.Core.Annotations.TextStrikeoutAnnotation
Text fieldannotation instanceof window.Core.Annotations.TextWidgetAnnotation
3D annotationannotation instanceof window.Core.Annotations.Model3DAnnotation
Tickannotation instanceof window.Core.Annotations.StampAnnotation && annotation.stampText === "Accepted"
Tracked changeannotation instanceof window.Core.Annotations.TextHighlightAnnotation && annotation.getCustomData('officeEditorTrackedChangeUID')
Underlineannotation instanceof window.Core.Annotations.TextUnderlineAnnotation

The following sample JavaScript code shows you how to use the properties listed above to determine annotation types in a PDF document.

JavaScript

1// Map of annotations with related information and annotationCheck methods for identification
2const map = {
3 'rectangle': {
4 icon: 'icon-tool-shape-rectangle',
5 annotationCheck: (annotation) => annotation instanceof window.Core.Annotations.RectangleAnnotation
6 },
7 // Other annotations...
8}
9
10// Method that iterates through the annotation map and calls each annotationCheck function to determine which type matches the annotation.
11// Returns the string key representing the type of the given annotation.
12const mapAnnotationToKey = (annotation) => Object.keys(map).find((key) => {
13 const { annotationCheck } = map[key];
14 return annotationCheck(annotation);
15});
16
17// Using this to identify an annotation
18const annotation = new window.Core.Annotations.RectangleAnnotation();
19// ... annotation setup ...
20const key = mapAnnotationToKey(annotation);
21console.log(key); // Output: 'rectangle'
22console.log(map[key].icon); // Output: 'icon-tool-shape-rectangle'

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales