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.
Configure custom context menu items in Context Menu, then handle taps with onCustomContextMenuItemTappedCallback.
CPDFReaderWidget(
document: documentPath,
configuration: configuration,
onCustomContextMenuItemTappedCallback: (identifier, event) {
if (event is! Map) {
return;
}
final data = Map<String, dynamic>.from(event);
final annotation = data['annotation'];
if (annotation is CPDFAnnotation) {
debugPrint('$identifier: ${annotation.type}');
}
},
);The callback receives the custom item's identifier and a dynamic event object. The Flutter SDK currently converts the event object to a Map<String, dynamic> whose fields depend on the context:
| Context | Main fields and runtime types |
|---|---|
| Screenshot | image: Uint8List |
| Selected text | text: String, rect: CPDFRectF, pageIndex: int |
| Long-pressed page | point: Map<String, double> containing x and y, pageIndex: int |
| Annotation | annotation: CPDFAnnotation |
| Content edit area | editArea: CPDFEditArea; text and image areas use their corresponding subclasses |
| Form field | widget: CPDFWidget |
Use the callback's first parameter to identify the menu item. Do not depend on the event Map also containing identifier.
For menu configuration, see Main Toolbar and Context Menu.