Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Annotations ​

Annotations are the markup objects users add to a PDF — highlights, shapes, free text, stamps, signatures, redactions, and more. This guide covers the UI-side annotation features and the Core annotation APIs.

Annotation rendering, the data model and PDF-space coordinates belong to the Core (instance.Core.Annotations, instance.Core.annotationManager). The UI creates annotations through tools and mirrors the selection and permissions in its stores.

Annotation types ​

Annotation classes are in instance.Core.Annotations:

CategoryClasses
Text markupTextHighlightAnnotation, TextUnderlineAnnotation, TextStrikeoutAnnotation, TextSquigglyAnnotation
ShapesRectangleAnnotation, EllipseAnnotation, LineAnnotation (also arrows), PolylineAnnotation, PolygonAnnotation (also clouds), ArcAnnotation
Free textFreeTextAnnotation (also callouts)
DrawingFreeHandAnnotation
NotesStickyAnnotation
Stamps & imagesStampAnnotation
LinksLink
Files & soundFileAttachmentAnnotation, SoundAnnotation
FormsTextWidgetAnnotation, CheckButtonWidgetAnnotation, RadioButtonWidgetAnnotation, ListWidgetAnnotation, ChoiceWidgetAnnotation, PushButtonWidgetAnnotation, SignatureWidgetAnnotation (see Forms)
SecurityRedactionAnnotation

Measurement annotations are line, polyline, polygon, rectangle, ellipse and arc annotations with measurement data.

UI APIs ​

Import / export buttons ​

The notes panel has buttons to import and export annotations. Hide them with their data elements:

javascript
UI.disableElements(['annotationExportButton', 'annotationImportButton']);
UI.enableElements(['annotationExportButton', 'annotationImportButton']);

Author / user ​

javascript
instance.Core.annotationManager.setCurrentUser('alice'); // author of new annotations
UI.setAuthor('alice');                                     // the "Author" field in the settings dialog
UI.enableFeatures([UI.Feature.LinkHighlighting]);          // highlight links

The initial user is set with the annotationUser option of ComPDFKitViewer().

Turn annotations off ​

javascript
UI.disableFeatures([UI.Feature.Annotations]);

Annotation popup ​

The annotation context menu is customizable — see Popups.

Core (annotation surface) ​

instance.Core.annotationManager provides the annotation APIs:

MethodPurpose
getAnnotationsList()List annotations.
addAnnotation(annotation) / addAnnotations(annotations)Add annotations.
deleteAnnotation(annotation) / deleteAnnotations(annotations)Delete annotations.
selectAnnotation(annotation) / getSelectedAnnotations() / deselectAllAnnotations()Selection.
redrawAnnotation(annotation)Redraw after changing properties.
exportAnnotations()Export to an XFDF string.
importAnnotations(xfdf)Import from an XFDF string, File or Blob.
setCurrentUser(name) / getCurrentUser()Author of new annotations.
enableReadOnlyMode() / disableReadOnlyMode()Read-only mode.
setPermissionCheckCallback(fn) / canModify(annotation)Permissions.

See Create Annotations and Import & Export Annotations.

Annotation state in the UI ​

StatePurpose
Selected annotationsDrive the annotation popup and the style panel.
Tool stylesThe default style of each annotation tool.
Current user / adminMirror annotationManager.getCurrentUser() and the admin flag; used for permissions.

The UI updates this state from the annotationSelected, annotationChanged and toolModeUpdated events.

Permission checks ​

  • isAdminUser (option, default true) — the user can modify every annotation.
  • isReadOnly (option) — open the document in read-only mode; annotations cannot be created or changed.
  • annotationManager.setPermissionCheckCallback((author, annotation) => boolean) — decide per annotation whether the current user can modify it. annotationManager.canModify(annotation) returns the result.

Examples ​

Hide annotation export and set the author ​

javascript
UI.disableElements(['annotationExportButton']);
instance.Core.annotationManager.setCurrentUser('alice');

Export annotations ​

javascript
const xfdf = await instance.Core.annotationManager.exportAnnotations();
console.log(xfdf);

List annotations ​

javascript
const annotations = instance.Core.annotationManager.getAnnotationsList();
console.log(annotations.length);