> 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/salesforce/forms/embedded-js.md).

# PDF Embedded JavaScript

Learn how PDF documents can contain embedded JavaScript (AcroJS) for interactive form fields. Discover how to enable, disable, and customize embedded JavaScript in WebViewer for enhanced user experien

PDF documents may contain embedded JavaScript (sometimes known as AcroJS) that is often run in response to events on form fields inside the document. This JavaScript executes in a special environment that contains a number of predefined functions for interacting with fields and the document.

Embedded JavaScript might be used for:

* Calculating a total based on the value of several fields
* Formatting a field to add a dollar sign at the front
* Validating the format of a date field and alerting the user if they entered it incorrectly

## In WebViewer

You don't need to do anything to enable embedded JavaScript execution, simply load a PDF document that contains embedded JavaScript and the code will run at the appropriate times. For example in response to clicks by the user or automatically when calculating a field value.

## Disabling

If you don't want embedded JavaScript to execute you can call [`disableEmbeddedJavaScript()`](https://sdk.apryse.com/api/web/Core.html#.disableEmbeddedJavaScript__anchor).

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

```js
// config.js
instance.Core.disableEmbeddedJavaScript();
```

{% endcode %}
{% endtab %}

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

```js
WebViewer(...)
// config.js
instance.CoreControls.disableEmbeddedJavaScript();
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Customization

WebViewer provides an API to customize the embedded JavaScript environment if you would like to change the behavior for some reason. The [`update`](https://sdk.apryse.com/api/web/Core.Annotations.Forms.EmbeddedJS.html#update__anchor) function provides access to the embedded environment and lets you make changes.

For example, Adobe Acrobat defines a global `ADBE` object that some older PDFs might check. So you could define the value to prevent certain popups from appearing.

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
Annotations.Forms.EmbeddedJS.update(scope => {
  // Scope represents the window scope that embedded javascript runs within
  // Define the ADBE namespace so that older PDFs will find it
  scope.ADBE = {};
});
```

{% endcode %}
{% 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/salesforce/forms/embedded-js.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.
