Remove PDF form fields in JavaScript

A form field can be removed by deleting its widget annotations. This will remove the ability to interact with the form field since widget annotations represent the appearances of form fields in a PDF document.

Remove all widgets and fields

When you delete a widget annotation its associated field will also be deleted (unless the field still has other associated widgets). In this code sample we delete all widgets which automatically delete all fields.

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, annotationManager, Annotations } = instance.Core;
4
5 documentViewer.addEventListener('annotationsLoaded', () => {
6 const annots = annotationManager.getAnnotationsList();
7
8 // Get all widget annotations.
9 const widgetAnnots = annots.filter(a => a instanceof Annotations.WidgetAnnotation)
10
11 // Remove the widget annotations.
12 // Associated fields will automatically be deleted.
13 annotationManager.deleteAnnotations(widgetAnnots);
14 });
15 });

Remove widgets and fields by name

To remove a specific field, find the field by its name and then delete the associated widget annotations.

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, annotationManager } = instance.Core;
4
5 documentViewer.addEventListener('annotationsLoaded', () => {
6 const fieldManager = annotationManager.getFieldManager();
7 const field = fieldManager.getField('fieldName');
8 if (field) {
9 annotationManager.deleteAnnotations(field.widgets);
10 }
11 });
12 });

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales