Skip to content

创建注释

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();