Skip to content
ComPDF
DemoFAQ

PDF Generation Template Editor

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

View on GitHub
Guides

Annotations

Use these callbacks to synchronize annotation property panels and observe annotation creation, selection, and undo or redo state. Annotation history uses a dedicated listener rather than CPDFEvent.

Callback or APIParametersTrigger
onAnnotationStyleDialogDismissedCallbackCPDFAnnotationType typeThe annotation properties panel closes.
controller.annotationHistoryManager.<br/>setOnHistoryChangedListener()bool canUndo, bool canRedoThe annotation undo/redo state changes.

CPDFReaderWidgetController.addEventListener() supports multiple callbacks for the same event. When the first listener for an event is added, the Flutter SDK asks the native SDK to start sending that event. Removing the last listener stops native delivery.

dart
void addEventListener(CPDFEvent event, Function(dynamic) callback);

bool removeEventListener(CPDFEvent event, Function(dynamic) callback);

void removeAllEventListeners([CPDFEvent? event]);

Event Index

EventEvent dataTrigger
CPDFEvent.annotationsCreatedCPDFAnnotationA non-form annotation is created.
CPDFEvent.annotationsSelectedCPDFAnnotationAn annotation is selected.
CPDFEvent.annotationsDeselectedCPDFAnnotation?An annotation is deselected.
CPDFEvent.pencilDrawingCompletedMap<String, dynamic>A Pencil drawing is saved (iOS only).
CPDFEvent.pencilDrawingDiscardedMap<String, dynamic>A Pencil drawing is discarded (iOS only).

Register annotation events and the annotation History Manager after the Reader is created:

dart
void _onReaderCreated(CPDFReaderWidgetController controller) {
  controller.addEventListener(
    CPDFEvent.annotationsCreated,
    (annotation) => debugPrint('Created: $annotation'),
  );
  controller.addEventListener(
    CPDFEvent.annotationsSelected,
    (annotation) => debugPrint('Selected: $annotation'),
  );
  controller.addEventListener(
    CPDFEvent.annotationsDeselected,
    (annotation) => debugPrint('Deselected: $annotation'),
  );

  controller.annotationHistoryManager.setOnHistoryChangedListener(
    (canUndo, canRedo) {
      debugPrint('Annotation history: undo=$canUndo, redo=$canRedo');
    },
  );
}

CPDFEvent currently covers creation and selection state. It does not report annotation updates and deletions, or save failures. To save explicitly and inspect the result, use the relevant save API instead of relying on onSaveCallback.

Pencil events are available only on iOS. Their event data provides type and pageIndex.