Skip to content
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:

  1. Obtain the document object.
  2. Get the page object where the form field to be deleted is located.
  3. Retrieve the list of form fields on that page.
  4. Locate the form field you want to delete from the list.
  5. 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]);