> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/forms/remove-fields.md).

# Remove PDF form fields in JavaScript

In this guide learn how to remove PDF form fields in JavaScript interactive form fields. The Apryse Web SDK streamlines secure, serverless document processing with robust support for JavaScript and Ty

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.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager, Annotations } = instance.Core;

    documentViewer.addEventListener('annotationsLoaded', () => {
      const annots = annotationManager.getAnnotationsList();

      // Get all widget annotations.
      const widgetAnnots = annots.filter(a => a instanceof Annotations.WidgetAnnotation)

      // Remove the widget annotations.
      // Associated fields will automatically be deleted.
      annotationManager.deleteAnnotations(widgetAnnots);
    });
  });
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer#annotationsLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:annotationsLoaded__anchor) [AnnotationManager.getAnnotationsList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getAnnotationsList__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.deleteAnnotations](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#deleteAnnotations__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('annotationsLoaded', () => {
      const annots = annotManager.getAnnotationsList();

      // Get all widget annotations.
      const widgetAnnots = annots.filter(a => a instanceof Annotations.WidgetAnnotation)

      // Remove the widget annotations.
      // Associated fields will automatically be deleted.
      annotManager.deleteAnnotations(widgetAnnots);
    });
  });
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer#annotationsLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:annotationsLoaded__anchor) [AnnotationManager.getAnnotationsList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getAnnotationsList__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.deleteAnnotations](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#deleteAnnotations__anchor)
{% endtab %}
{% endtabs %}

## Remove widgets and fields by name

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

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager } = instance.Core;

    documentViewer.addEventListener('annotationsLoaded', () => {
      const fieldManager = annotationManager.getFieldManager();
      const field = fieldManager.getField('fieldName');
      if (field) {
        annotationManager.deleteAnnotations(field.widgets);
      }
    });
  });
```

{% endcode %}

[DocumentViewer.getAnnotationsLoadedPromise](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getAnnotationsLoadedPromise__anchor) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.getField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#getField__anchor) [Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [AnnotationManager.deleteAnnotations](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#deleteAnnotations__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager } = instance;

    docViewer.on('annotationsLoaded', () => {
      const fieldManager = annotManager.getFieldManager();
      const field = fieldManager.getField('fieldName');
      if (field) {
        annotManager.deleteAnnotations(field.widgets);
      }
    });
  });
```

{% endcode %}

[DocumentViewer.getAnnotationsLoadedPromise](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getAnnotationsLoadedPromise__anchor) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.getField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#getField__anchor) [Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [AnnotationManager.deleteAnnotations](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#deleteAnnotations__anchor)
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/forms/remove-fields.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
