> 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/reusable-content/web/web-loading-options.md).

# web/loading-options

***

### Loading options

WebViewer provides various options to load a document. Whether you are loading a document through the `initialDoc` option in the constructor or calling `loadDocument` after mounting, you can always provide options to load your document.

#### The extension option

When loading a document using a URL, WebViewer will use the URL to determine what type of file it is. For example `http://myserver.com/myfile.docx` ends with `.docx` so WebViewer will assume it's a docx file. However, what happens if you are loading from a blob or extensionless URL? That's where the `extension` option comes in.

You can use the `extension` option to explicitly tell WebViewer what type of file it is. For example, `extension: 'docx'` or `extension: 'png'`. By default WebViewer will assume it's a PDF file but that might not be correct.

**Via WebViewer Constructor**

```js
WebViewer({
  path: '../../../lib',
  initialDoc: 'http://<documentserver>/FileDownload?docId=foo',
  extension: 'docx',
  ...
}, document.getElementById('viewer'))
  .then(instance => {
    // ...
  });
```

[WebViewer Options](https://sdk.apryse.com/api/web/global.html#WebViewerOptions__anchor)

**Via API**

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

```js
WebViewer(...)
  .then(instance => {
    instance.UI.loadDocument('http://<documentserver>/FileDownload?docId=foo', {
      extension: 'docx'
    });

    //...
  });
```

[UI](https://sdk.apryse.com/api/web/UI.html) [UI.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)
{% endtab %}

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

```js
WebViewer(...)
  .then(instance => {
    instance.loadDocument('http://<documentserver>/FileDownload?docId=foo', {
      extension: 'docx'
    });

    //...
  });
```

[WebViewerInstance.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)
{% endtab %}
{% endtabs %}

#### The filename option

The `filename` option is used to indicate the name of the file when you press the download button in the viewer. However, the option can also be used as a way of indicating the type of file you are opening when the URL does not end with a file extension. Note that the `extension` property has precedence over `filename` for determining the document type.

**Via WebViewer Constructor**

```js
WebViewer({
  path: '../../../lib',
  initialDoc: 'http://<documentserver>/FileDownload?docId=foo',
  filename: 'report.docx',
  ...
}, document.getElementById('viewer'))
  .then(instance => {
    // ...
  });
```

[WebViewer Options](https://sdk.apryse.com/api/web/global.html#WebViewerOptions__anchor)

**Via API**

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

```js
WebViewer(...)
  .then(instance => {
    instance.UI.loadDocument('http://<documentserver>/FileDownload?docId=foo', {
      filename: 'report.docx'
    });

    //...
  });
```

[UI](https://sdk.apryse.com/api/web/UI.html) [UI.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)
{% endtab %}

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

```js
WebViewer(...)
  .then(instance => {
    instance.loadDocument('http://<documentserver>/FileDownload?docId=foo', {
      filename: 'report.docx'
    });

    //...
  });
```

[WebViewerInstance.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)
{% endtab %}
{% endtabs %}

#### The customHeaders option

If your document server requires additional options in the HTTP request, you can use the second argument in `loadDocument` function to pass them. This is especially useful when you need the `Authorization` header in the request with your auth key.

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

```js
WebViewer(...)
  .then(instance => {
    instance.UI.loadDocument('https://myserver.com/myfile.pdf', {
      customHeaders: {
        Authorization: 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'
      }
    });
  });
```

[UI](https://sdk.apryse.com/api/web/UI.html) [UI.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)
{% endtab %}

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

```js
WebViewer(...)
  .then(instance => {
    instance.loadDocument('https://myserver.com/myfile.pdf', {
      customHeaders: {
        Authorization: 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'
      }
    });
  });
```

[WebViewerInstance.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)
{% endtab %}
{% endtabs %}

#### The password option

For password-protected documents, it can be provided during the `loadDocument` call via the options argument. It can either take the password string or a function that will eventually provide a password via a callback provided as a parameter.

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

```js
WebViewer(...)
  .then(instance => {
    instance.UI.loadDocument('https://myserver.com/myfile.pdf', {
      password: 'asdf'
    });
  });
```

[UI](https://sdk.apryse.com/api/web/UI.html) [UI.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)
{% endtab %}

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

```js
WebViewer(...)
  .then(instance => {
    instance.loadDocument('https://myserver.com/myfile.pdf', {
      password: 'asdf'
    });
  });
```

[WebViewerInstance.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)
{% endtab %}
{% endtabs %}

#### The customHandlerId option

An Apryse [custom security handler](/web/security/custom-handler.md) easily encrypts and secures documents with our algorithm to allow opening the document only in WebViewer (or PDFNet).

For these types of documents, it is necessary to provide the integer custom handler ID along with the password.

{% hint style="warning" %}
This is only available to WebViewer 8.2+.
{% endhint %}

```js
WebViewer(...)
  .then(instance => {
    instance.UI.loadDocument('https://myserver.com/myfile.pdf', {
      password: 'asdf',
      customHandlerId: 42
    });
  });
```

[UI](https://sdk.apryse.com/api/web/UI.html) [UI.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)


---

# 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/reusable-content/web/web-loading-options.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.
