> 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/advanced/customizing-setup.md).

# Setup options when customizing WebViewer

Enhance WebViewer with customizations using two setup options: accessing the WebViewer instance within your app or utilizing a config file for standalone JavaScript execution inside WebViewer's iframe

There are two ways of adding customization to WebViewer, the first way is by accessing the WebViewer instance within your app and the second is by using a [config file](/web/advanced/config-files.md), which is a stand-alone JavaScript file executed inside [WebViewer's iframe](/web/what-is-webviewer/wv-inside.md#webviewers-iframe).

### Config file

You can organize your custom code in a separate JavaScript file that is executed in the context of the [iframe](/web/what-is-webviewer/wv-inside.md#webviewers-iframe). In this way, you have direct access to the iframe window and document, and you can use WebViewer's global methods directly. See more details about [config files](/web/advanced/config-files.md).

Config files are recommended when you are hosting the WebViewer lib folder on a separate server from your application. Since the config file is executed directly in the iframe there are no cross origin issues.

<pre class="language-js" data-line-numbers><code class="lang-js">// app.js
// Instantiate WebViewer
WebViewer({
  path: 'https://myotherserver.com/webviewer/lib',
  licenseKey: '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>'
  initialDoc: '/files/webviewer-demo-annotated.pdf',
  config: 'config.js' // path/to/your/config.js
}, document.getElementById('viewer'));
</code></pre>

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

```js
// config.js executed inside the iframe
instance.UI.addEventListener(instance.UI.Events.VIEWER_LOADED, () => {
  const { documentViewer, annotationManager } = instance.Core;

  // Add customization here
  documentViewer.setMargin(20);
  documentViewer.addEventListener('fitModeUpdated', fitMode => {
    console.log('fit mode changed');
  });

  instance.UI.disableElement('searchButton');
  instance.UI.setTheme('dark');
});

instance.UI.addEventListener(instance.UI.Events.DOCUMENT_LOADED, () => {
  const { documentViewer, annotationManager } = instance.Core;

  // Add customization here
  // Draw rectangle annotation on first page
  // "Annotations" can be directly accessed since we're inside the iframe
  const rectangle = new Annotations.RectangleAnnotation();
  rectangle.PageNumber = 1;
  rectangle.X = 100;
  rectangle.Y = 100;
  rectangle.Width = 250;
  rectangle.Height = 250;
  rectangle.Author = annotationManager.getCurrentUser();
  annotationManager.addAnnotation(rectangle);
  annotationManager.drawAnnotations(rectangle.PageNumber);
})
```

{% endcode %}
{% endtab %}

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

```js
// config.js executed inside the iframe
window.addEventListener('viewerLoaded', () => {
  const docViewer = readerControl.docViewer;
  const annotManager = docViewer.getAnnotationManager();

  // Add customization here
  docViewer.setMargin(20);
  docViewer.on('fitModeUpdated', fitMode => {
    console.log('fit mode changed');
  });

  readerControl.disableElement('searchButton');
  readerControl.setTheme('dark');
});

window.addEventListener('documentLoaded', () => {
  const docViewer = readerControl.docViewer;
  const annotManager = docViewer.getAnnotationManager();

  // Add customization here
  // Draw rectangle annotation on first page
  // "Annotations" can be directly accessed since we're inside the iframe
  const rectangle = new Annotations.RectangleAnnotation();
  rectangle.PageNumber = 1;
  rectangle.X = 100;
  rectangle.Y = 100;
  rectangle.Width = 250;
  rectangle.Height = 250;
  rectangle.Author = annotManager.getCurrentUser();
  annotManager.addAnnotation(rectangle);
  annotManager.drawAnnotations(rectangle.PageNumber);
})
```

{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/web/advanced/customizing-setup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
