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.
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 API | Parameters | Trigger |
|---|---|---|
onAnnotationStyleDialogDismissedCallback | CPDFAnnotationType type | The annotation properties panel closes. |
controller.annotationHistoryManager.<br/>setOnHistoryChangedListener() | bool canUndo, bool canRedo | The 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.
void addEventListener(CPDFEvent event, Function(dynamic) callback);
bool removeEventListener(CPDFEvent event, Function(dynamic) callback);
void removeAllEventListeners([CPDFEvent? event]);Event Index
| Event | Event data | Trigger |
|---|---|---|
CPDFEvent.annotationsCreated | CPDFAnnotation | A non-form annotation is created. |
CPDFEvent.annotationsSelected | CPDFAnnotation | An annotation is selected. |
CPDFEvent.annotationsDeselected | CPDFAnnotation? | An annotation is deselected. |
CPDFEvent.pencilDrawingCompleted | Map<String, dynamic> | A Pencil drawing is saved (iOS only). |
CPDFEvent.pencilDrawingDiscarded | Map<String, dynamic> | A Pencil drawing is discarded (iOS only). |
Register annotation events and the annotation History Manager after the Reader is created:
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.