PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
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 classes are in instance.Core.Annotations:
| Category | Classes |
|---|---|
| Text markup | TextHighlightAnnotation, TextUnderlineAnnotation, TextStrikeoutAnnotation, TextSquigglyAnnotation |
| Shapes | RectangleAnnotation, EllipseAnnotation, LineAnnotation (also arrows), PolylineAnnotation, PolygonAnnotation (also clouds), ArcAnnotation |
| Free text | FreeTextAnnotation (also callouts) |
| Drawing | FreeHandAnnotation |
| Notes | StickyAnnotation |
| Stamps & images | StampAnnotation |
| Links | Link |
| Files & sound | FileAttachmentAnnotation, SoundAnnotation |
| Forms | TextWidgetAnnotation, CheckButtonWidgetAnnotation, RadioButtonWidgetAnnotation, ListWidgetAnnotation, ChoiceWidgetAnnotation, PushButtonWidgetAnnotation, SignatureWidgetAnnotation (see Forms) |
| Security | RedactionAnnotation |
Measurement annotations are line, polyline, polygon, rectangle, ellipse and arc annotations with measurement data.
The notes panel has buttons to import and export annotations. Hide them with their data elements:
UI.disableElements(['annotationExportButton', 'annotationImportButton']);
UI.enableElements(['annotationExportButton', 'annotationImportButton']);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 linksThe initial user is set with the annotationUser option of ComPDFKitViewer().
UI.disableFeatures([UI.Feature.Annotations]);The annotation context menu is customizable — see Popups.
instance.Core.annotationManager provides the annotation APIs:
| Method | Purpose |
|---|---|
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.
| State | Purpose |
|---|---|
| Selected annotations | Drive the annotation popup and the style panel. |
| Tool styles | The default style of each annotation tool. |
| Current user / admin | Mirror annotationManager.getCurrentUser() and the admin flag; used for permissions. |
The UI updates this state from the annotationSelected, annotationChanged and toolModeUpdated events.
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.UI.disableElements(['annotationExportButton']);
instance.Core.annotationManager.setCurrentUser('alice');const xfdf = await instance.Core.annotationManager.exportAnnotations();
console.log(xfdf);const annotations = instance.Core.annotationManager.getAnnotationsList();
console.log(annotations.length);