Skip to content
ComPDF
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

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 import/export APIs.

Annotation rendering, data model, and PDF-space coordinate handling live in the closed-source Core engine (packages/core/src/annotation/). The UI layer (documented here) drives the engine through the core bridge and mirrors annotation state in the document Pinia store.

Annotation types

CategoryTypes
Text markupHighlight, Underline, Strikeout, Squiggly
ShapesRectangle (square), Circle, Line, Arrow, Polyline, Polygon, Cloudy, Arc, Curve
Free textFreetext, Callout
DrawingInk
Stamps & imagesStamp, Image
LinksLink
FormsTextfield, Checkbox, Radiobutton, Listbox, Combobox, Pushbutton, Signature (see Forms)
SecurityRedaction, Remove (see content editor / security)

Type aliases

Some types share engine implementation:

  • circle without measure → square
  • ink with measure → curve
  • ink with arc points → arc

UI APIs

Import / export enable/disable

javascript
UI.disableAnnotationExport();   // useViewer.setAnnotationExport(false)
UI.enableAnnotationExport();    // useViewer.setAnnotationExport(true)
UI.disableAnnotationImport();   // useViewer.setAnnotationImport(false)
UI.enableAnnotationImport();    // useViewer.setAnnotationImport(true)

These toggle the annotation.isAnnotationExport / annotation.isAnnotationImport flags in the viewer store, controlling whether the UI offers import/export of annotations.

Author / user

javascript
UI.setCurrentUser('alice');     // falls back to 'Guest'
UI.setAnnotator('alice');       // same store action as setCurrentUser
UI.setAuthor('alice');          // empty string if falsy
UI.setHighlightLink(true);      // toggle link highlighting

Annotation popup

The annotation context menu is customizable — see Popups.

Core bridge (annotation surface)

The core bridge (src/core/) exposes the engine's annotation APIs on instance.Core:

FunctionPurpose
getAnnotationsListList annotations.
getAnnotationManagerGet the annotation manager.
getAnnotationHistoryManagerGet the undo/redo history manager.
importAnnotations / exportAnnotationsXFDF/JSON import/export.
exportXfdf / saveAnnotationsSave annotation data.
removeAllAnnotationsClear all annotations.
selectAnnotation / jumpToAnnotationSelection & navigation.
setAnnotationStylesUpdate annotation styles.
addAnnotationImageAdd an image annotation.
handleReplyAnnotationReply threads.
setUnselectableAnnotationTypes / getUnselectableAnnotationTypesSelection control.
enableAutoSelectOnCreate / disableAutoSelectOnCreateAuto-select on creation.
updateViewWithColorIndexColor-index view update.
showPopup / handlePopupPopup control.
setAnnotatorSet the annotator name in the engine.
getDynamicStampPreview / getStampRect / handleStampStamp helpers.
setHighlightLink / setHighlightFormHighlight toggles.

Annotation state in the UI

The document store mirrors annotation state for the UI:

  • annotations — array (wrapped in shallowReactive via initAnnotations), managed by page index.
  • selectedAnnotation / selected — the currently selected annotation.
  • annotationsCount — count (formatted as "N annotation(s)" by the getAnnotationsCount getter).
  • getAllAnnotations getter — groups annotations by page index, filtering by a type allow-list and excluding replies.
  • propertyPanel — the property-panel model for the selected annotation/form field.

initAnnotations / setAnnotations(annotation, type) manage the array by page index (add/delete/update). The store pushes changes into the engine — for example, setActiveToolColor writes the color and calls core.setTool.

Permission checks

helpers/annotationPermissions.js exposes canCopyAnnotations({ isReadOnly, isUserAdmin, currentAuthor, annotations }):

  • false if read-only.
  • true if the user is an admin.
  • Otherwise requires every annotation's author to equal currentAuthor.

Examples

Disable annotation export and set the author

javascript
UI.disableAnnotationExport();
UI.setAuthor('alice');

Export annotations via the bridge

javascript
const xfdf = await instance.Core.exportXfdf();

List annotations

javascript
const annotations = instance.Core.getAnnotationsList();