Skip to content

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 TypeEnum Value
Text Notenote
Highlighthighlight
Underlineunderline
Squigglysquiggly
Strikeoutstrikeout
Inkink
Ink Eraserink_eraser
Pencilpencil
Circlecircle
Rectanglesquare
Arrowarrow
Lineline
Free Textfreetext
Signaturesignature
Stampstamp
Linklink
Soundsound
Exit Drawing Modeunknown

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