Skip to content
ComPDF
DemoAPI ReferenceFAQ

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 the content-editor History Manager for undo/redo state.

Selection Events

EventEvent dataTrigger
CPDFEvent.EDITOR_SELECTION_SELECTEDCPDFEditAreaEditable text, image, or path content is selected.
CPDFEvent.EDITOR_SELECTION_DESELECTEDCPDFEditArea | nullThe content-editor selection is cleared.

History State

ScenarioRegistration APICallback parametersReplacement rule
Content-editor undo/redo statepdfReaderRef.current?.
_editManager.historyManager.
setOnHistoryStateChangedListener()
pageIndex: number, canUndo: boolean, canRedo: booleanSetting again replaces the previous callback.
tsx
const reader = pdfReaderRef.current;
if (reader) {
  const editorHistory = reader._editManager.historyManager;
  const initialCanUndo = await editorHistory.canUndo();
  const initialCanRedo = await editorHistory.canRedo();
  console.log('Initial editor history:', initialCanUndo, initialCanRedo);

  editorHistory.setOnHistoryStateChangedListener(
    (pageIndex, canUndo, canRedo) => {
      console.log('Editor history:', pageIndex, canUndo, canRedo);
    },
  );
}

EDITOR_SELECTION_SELECTED can be CPDFEditTextArea, CPDFEditImageArea, or CPDFEditArea with type === CPDFEditType.PATH. On Android, editor deselection normally returns null; on iOS it can return the deselected area. RN does not define a dedicated path-area class.

Each Manager keeps one callback and does not emit an initial value. Query canUndo() and canRedo() when initializing controls. On iOS, the content-editor listener may also fire after a page change to report the new page's undo/redo state.

The current TypeScript class exposes _annotationsHistoryManager and _editManager, but their leading underscores indicate lower API stability. A future SDK version may replace them with formal public getters.

See Undo and Redo for the operation APIs.