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.
Content editing uses CPDFEvent for selection changes and its History Manager for undo/redo state.
| Event | Event data | Trigger |
|---|---|---|
CPDFEvent.editorSelectionSelected | CPDFEditArea? | An editable text, image, or path area is selected. |
CPDFEvent.editorSelectionDeselected | null | The content editor selection is cleared. |
When the content editor properties panel closes, onContentEditorStyleDialogDismissedCallback returns CPDFContentEditorType. The callback can be used to synchronize application editing state and does not change the SDK's default behavior.
| Scenario | Registration API | Callback parameters | Replacement rule |
|---|---|---|---|
| Content editor undo/redo state | controller.editManager.historyManager. | int pageIndex, bool canUndo, bool canRedo | Calling the setter again replaces the previous callback. |
void _onReaderCreated(CPDFReaderWidgetController controller) {
controller.addEventListener(
CPDFEvent.editorSelectionSelected,
(event) => debugPrint('Selected edit area: $event'),
);
controller.addEventListener(
CPDFEvent.editorSelectionDeselected,
(_) => debugPrint('Editor selection cleared'),
);
controller.editManager.historyManager.setOnHistoryChangedListener(
(pageIndex, canUndo, canRedo) {
debugPrint(
'Editor history: page=$pageIndex, undo=$canUndo, redo=$canRedo',
);
},
);
}editorSelectionSelected returns CPDFEditTextArea, CPDFEditImageArea, or CPDFEditArea (with type == CPDFEditAreaType.path for a path). editorSelectionDeselected always returns null; Flutter does not define a dedicated path-area subclass.
Each History Manager stores one callback. Calling setOnHistoryChangedListener() again replaces it. For the undo, redo, and state-query APIs, see Undo and Redo.
On iOS, the content editor History Listener can also run after a page change to report the state of the current page.
A History Listener reports changes that occur after registration; it does not send an initial value. Query canUndo() and canRedo() when initializing undo and redo controls:
final history = controller.editManager.historyManager;
final canUndo = await history.canUndo();
final canRedo = await history.canRedo();