Skip to content
ComPDF
Guides

Annotations

The ComPDF React Native SDK supports a variety of annotation events. Common annotation events include:

Event NameDescription
onAnnotationCreationPreparedTriggered when the user is about to create a signature, stamp, hyperlink, or image annotation. Returns the annotation type.
CPDFEvent.ANNOTATIONS_CREATEDTriggered when the user creates an annotation. Returns the created annotation data.
CPDFEvent.ANNOTATIONS_SELECTEDTriggered when the user selects an annotation. Returns the selected annotation data.
CPDFEvent.ANNOTATIONS_DESELECTEDTriggered when the user deselects an annotation. Returns the deselected annotation data.

onAnnotationCreationPrepared

This event is triggered when entering annotation creation mode, either by clicking the signature, stamp, hyperlink, or image tools in the bottom toolbar, or programmatically via pdfReaderRef.current.setAnnotationMode().

Using this callback, you can show a custom selection UI in your React Native app instead of the default ComPDF selection dialogs. To disable the default selection dialogs for these four types of annotations, configure CPDFConfiguration as follows:

tsx
ComPDFKit.getDefaultConfig({
  annotationsConfig: {
    autoShowLinkDialog: false,
    autoShowPicPicker: false,
    autoShowSignPicker: false,
    autoShowStampPicker: false,
  }
});

To listen for the onAnnotationCreationPrepared event, pass a callback function when creating the CPDFReaderView:

tsx
<CPDFReaderView
  ref={pdfReaderRef}
  document={samplePDF}
  configuration={ComPDFKit.getDefaultConfig({
    modeConfig: {
      initialViewMode: "annotations",
    },
    annotationsConfig: {
      autoShowLinkDialog: false,
      autoShowPicPicker: false,
      autoShowSignPicker: false,
      autoShowStampPicker: false,
    }
  })}
  onAnnotationCreationPrepared={(type, annotation) => {
    // Triggered when entering creation mode for signatures, stamps, or image annotations
    // Hyperlink annotations trigger after the user draws a rectangle on the page and lifts their finger
    // You can display a custom selection UI for signatures, stamps, images, etc.
  }}
/>

Insert Signature

After selecting a signature image, insert it using:

tsx
await controller.prepareNextSignature('/path/to/signature.png');

Insert Stamp

After selecting a standard, image, or text stamp, insert it using:

tsx
// Insert a standard stamp. Check the CPDFStandardStamp enum for available types
await pdfReaderRef.current?.prepareNextStamp({ standardStamp: CPDFStandardStamp.Approved });

// Insert an image stamp
await pdfReaderRef.current?.prepareNextStamp({ imagePath: '/path/to/stamp.png' });

// Insert a text stamp
await pdfReaderRef.current.prepareNextStamp({
  textStamp: {
    content: "ComPDF",
    date: CPDFDateUtil.getTextStampDate({
      timeSwitch: true,
      dateSwitch: true,
    }),
    color: CPDFTextStampColor.blue,
    shape: CPDFTextStampShape.leftTriangle,
  },
});

This allows your React Native app to fully customize the selection process for signatures and stamps while leveraging ComPDF’s powerful annotation creation features.


Listening to Other Annotation Events

You can listen to other annotation events after creating the CPDFReaderView:

tsx
pdfReaderRef.current?.addEventListener(
  CPDFEvent.ANNOTATIONS_CREATED,
  (annotation) => {
    // 'annotation' is a CPDFAnnotation object or one of its subclasses
  }
);

pdfReaderRef.current?.addEventListener(
  CPDFEvent.ANNOTATIONS_SELECTED,
  (annotation) => {
    // 'annotation' is a CPDFAnnotation object or one of its subclasses
  }
);

pdfReaderRef.current?.addEventListener(
  CPDFEvent.ANNOTATIONS_DESELECTED,
  (annotation) => {
    // 'annotation' is a CPDFAnnotation object or one of its subclasses
  }
);