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

Reader State and Interface Callbacks

The ComPDF Flutter SDK provides reader-level callbacks through CPDFReaderWidget. Use these callbacks for viewer lifecycle and UI events.

Available Callbacks

CallbackTrigger TimingPayload
onCreatedReader and controller are readyCPDFReaderWidgetController controller
onPageChangedCurrent page changesint pageIndex
onSaveCallbackThe Reader completes a save. For an application-initiated save, use the relevant Future<bool> resultNo payload
onFillScreenChangedFullscreen state changesbool isFillScreen
onTapMainDocAreaCallbackUser taps the main PDF page areaNo payload
onPageEditDialogBackPressUser taps the back button in the page edit dialogNo payload
onIOSClickBackPressediOS top-left reader back button is tappedNo payload
onSearchBackButtonTappedCallbackUser taps the back button in the search viewNo payload
onAddWatermarkDialogDismissedCallbackAdd watermark dialog is dismissedNo payload

Example Usage

dart
CPDFReaderWidget(
  document: documentPath,
  configuration: configuration,
  onCreated: (controller) {
    // Store the controller if listener events are needed later.
  },
  onPageChanged: (int pageIndex) {
    debugPrint('Current page: $pageIndex');
  },
  onSaveCallback: () {
    debugPrint('The native Reader reported a successful save');
  },
  onFillScreenChanged: (bool isFillScreen) {
    debugPrint('Fill screen: $isFillScreen');
  },
  onTapMainDocAreaCallback: () {
    debugPrint('Main document area tapped');
  },
  onPageEditDialogBackPress: () {
    debugPrint('Back button pressed in page edit dialog');
  },
  onIOSClickBackPressed: () {
    debugPrint('iOS back button pressed');
  },
  onSearchBackButtonTappedCallback: () {
    debugPrint('Search back button tapped');
  },
  onAddWatermarkDialogDismissedCallback: () {
    debugPrint('Add watermark dialog dismissed');
  },
);

Note

  • Widget callbacks follow the CPDFReaderWidget lifecycle and are not removed with removeEventListener().
  • onSearchBackButtonTappedCallback is useful when you manage search state on the Flutter side.
  • onAddWatermarkDialogDismissedCallback fires after the add watermark panel closes. Use it to restore custom UI state or refresh watermark-related controls.