Guides
Delete Annotations
The ComPDFKit React Native SDK provides APIs to delete selected annotations. The steps to delete annotations are as follows:
- Obtain the document object.
- Retrieve the page object where the annotation is located.
- Get the list of annotations on that page.
- Find the annotation you want to delete from the list.
- 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.