Guides
Delete Form Fields
The ComPDFKit ReactNative SDK supports deleting selected form fields via API. The steps to remove a form field are as follows:
- Obtain the document object.
- Get the page object where the form field to be deleted is located.
- Retrieve the list of form fields on that page.
- Locate the form field you want to delete from the list.
- Delete the form field.
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 widgets = await page?.getWidgets();
if (widgets[0]) {
await page.removeWidget(widgets[0]);
}
// Or use this shortcut
pdfReaderRef?.current?._pdfDocument.removeWidget(widgets[0]);