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

Content Editing Events and History State

Content editing uses CPDFEvent for selection changes and its History Manager for undo/redo state.

EventEvent dataTrigger
CPDFEvent.editorSelectionSelectedCPDFEditArea?An editable text, image, or path area is selected.
CPDFEvent.editorSelectionDeselectednullThe 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.

ScenarioRegistration APICallback parametersReplacement rule
Content editor undo/redo statecontroller.editManager.historyManager.
setOnHistoryChangedListener()
int pageIndex, bool canUndo, bool canRedoCalling the setter again replaces the previous callback.
dart
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:

dart
final history = controller.editManager.historyManager;
final canUndo = await history.canUndo();
final canRedo = await history.canRedo();