Guides
Viewer
The ComPDF Flutter SDK provides reader-level callbacks through CPDFReaderWidget. Use these callbacks for viewer lifecycle and UI events.
Available Callbacks
| Callback | Trigger Timing | Payload |
|---|---|---|
onPageChanged | Current page changes | int pageIndex |
onSaveCallback | Document save completes | No payload |
onFillScreenChanged | Fullscreen state changes | bool isFullScreen |
onTapMainDocAreaCallback | User taps the main PDF page area | No payload |
onPageEditDialogBackPress | User taps the back button in the page edit dialog | No payload |
onIOSClickBackPressed | iOS top-left reader back button is tapped | No payload |
onSearchBackButtonTappedCallback | User taps the back button in the search view | No payload |
onAddWatermarkDialogDismissedCallback | Add watermark dialog is dismissed | No 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('Document saved successfully');
},
onFillScreenChanged: (bool isFullScreen) {
debugPrint('Is full screen: $isFullScreen');
},
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
onSearchBackButtonTappedCallbackis useful when you manage search state on the Flutter side.onAddWatermarkDialogDismissedCallbackfires after the add watermark panel closes. Use it to restore custom UI state or refresh watermark-related controls.