Skip to content
Guides

Delete Annotations

The ComPDFKit React Native SDK provides APIs to delete selected annotations. The steps to delete annotations are as follows:

  1. Obtain the document object.
  2. Retrieve the page object where the annotation is located.
  3. Get the list of annotations on that page.
  4. Find the annotation you want to delete from the list.
  5. Delete the specified annotation.

Example code:

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

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

// Get the page object at a specific index
const page = pdfReaderRef?.current?._pdfDocument.pageAtIndex(0);
// Get all annotations on the page
const annotations = await page?.getAnnotations();
if (annotations[0]) {
  await page.removeAnnotation(annotations[0]);
}
// Or use this shortcut
pdfReaderRef?.current?._pdfDocument.removeAnnotation(annotations[0]);

Alternatively, you can remove all annotations from the current document by calling the removeAllAnnotations() method.

  • The return value is a boolean indicating whether the operation was successful.

Example code:

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

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

const removeResult = await pdfReaderRef.current?.removeAllAnnotations();

Note: This method does not delete hyperlink annotations.