On this page
Create Annotations
ComPDFKit supports a wide variety of annotation types, including text notes, links, shapes, highlights, stamps, freehand drawings, and audio annotations, fully meeting diverse annotation requirements.
Creating Annotations
With CPDFReaderView, users can enter annotation mode and create annotations via touch interaction. The annotation type can be set using the setAnnotationMode() method.
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);
The CPDFAnnotationType enum supports the following annotation types:
Annotation Type | Enum Value |
---|---|
Text Note | note |
Highlight | highlight |
Underline | underline |
Squiggly | squiggly |
Strikeout | strikeout |
Ink | ink |
Ink Eraser | ink_eraser |
Pencil | pencil |
Circle | circle |
Rectangle | square |
Arrow | arrow |
Line | line |
Free Text | freetext |
Signature | signature |
Stamp | stamp |
Link | link |
Sound | sound |
Exit Drawing Mode | unknown |
Exiting Annotation Mode
To exit annotation mode after finishing the operation, call:
dart
await _controller?.setAnnotationMode(CPDFAnnotationType.unknown);
Get Current Annotation Type
You can retrieve the current annotation type to check whether you are in annotation mode or determine the selected tool:
dart
CPDFAnnotationType currentType = await _controller?.getAnnotationMode();