PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
在上下文菜单中配置自定义菜单项,再通过 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}');
}
},
);回调会返回自定义菜单项的 identifier 和动态事件对象。当前 Flutter SDK 会将事件对象转换为 Map<String, dynamic>,字段取决于菜单所在的上下文:
| 上下文 | 主要字段和运行时类型 |
|---|---|
| 截图 | image: Uint8List |
| 选中文本 | text: String、rect: CPDFRectF、pageIndex: int |
| 长按页面 | 包含 x、y 的 point: Map<String, double>、pageIndex: int |
| 注释 | annotation: CPDFAnnotation |
| 内容编辑区域 | editArea: CPDFEditArea,文本和图片区域使用对应的子类 |
| 表单字段 | widget: CPDFWidget |
请使用回调的第一个参数识别菜单项,不要依赖事件 Map 中同时包含 identifier。