创建注释
ComPDFKit 支持多种类型的注释,包括文本注释、链接、图形、高亮、图章、手写标注以及音频注释,全面满足不同的注释需求。
创建注释
通过 CPDFReaderWidget,用户可以进入注释模式并通过触摸操作添加注释。注释的类型通过 setAnnotationMode() 方法设置。
dart
CPDFReaderWidgetController? _controller;
// Initialize CPDFReaderWidget and get the controller in the onCreated callback
CPDFReaderWidget(
document: widget.documentPath,
password: widget.password,
configuration: widget.configuration,
onCreated: (controller) {
setState(() {
_controller = controller;
});
},
);
await _controller?.setAnnotationMode(CPDFAnnotationType.highlight);完整支持的注释类型(CPDFAnnotationType 枚举)包括:
| 注释类型 | 枚举值 |
|---|---|
| 文本注释 | note |
| 高亮 | highlight |
| 下划线 | underline |
| 波浪线 | squiggly |
| 删除线 | strikeout |
| 墨水 | ink |
| 墨水橡皮擦 | ink_eraser |
| 铅笔 | pencil |
| 圆形 | circle |
| 矩形 | square |
| 箭头 | arrow |
| 线段 | line |
| 文本 | freetext |
| 电子签名 | signature |
| 图章注释 | stamp |
| 图片 | pictures |
| 链接 | link |
| 音频 | sound |
| 退出绘制模式 | unknown |
退出注释创建模式
完成注释后,可调用以下方法退出注释状态:
dart
await _controller?.setAnnotationMode(CPDFAnnotationType.unknown);获取当前绘制注释类型
可用于判断当前是否处于注释状态或获取当前选中的注释工具:
dart
CPDFAnnotationType currentType = await _controller?.getAnnotationMode();