Create Annotations
ComPDF 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 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:
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();