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.

tsx
const pdfReaderRef = useRef<CPDFReaderView>(null);

<CPDFReaderView
  ref={pdfReaderRef}
  document={samplePDF}
  configuration={ComPDFKit.getDefaultConfig({
  })}/>

await pdfReaderRef.current?.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:

tsx
await pdfReaderRef.current?.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:

tsx
const annotationMode = await pdfReaderRef.current?.getAnnotationMode();