> 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/webviewer-server/wv-server-wrapper.md).

# WebViewer Server API Wrapper

Download the WVSApiWrapper.js script from our WebViewer Server tools section for extended API functionality. Use it for PDF and thumbnail fetching with more features to come. The Apryse Web SDK stream

We offer a script file in the tools section of our WebViewer Server download package called `WVSApiWrapper.js`, this script allows the use of WebViewer Server using the extended API. This script currently provides functionality for PDF fetching and thumbnail fetching with future features planned.

This wrapper can be used with your WebViewer Server without the need for WebViewer. We have written it as a single Javascript file with no dependencies to allow ease of deployment.

## Usage

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

```js
<script src="./WVSApiWrapper.js"></script>
<script>
  var wvs = WebViewerServer({
      serverUrl: "http://<HOST_IP_ADDRESS or localhost>:8090"
  });

  wvs.getPDF({  uri: 'http://<HOST_IP_ADDRESS or localhost>:8090/myfile.pdf' }).then(function (pdfLink) {
      window.open(pdfLink, "theFrame");
  });
</script>

<html>
    <iframe name="theFrame" width="1000" height="1000" ></iframe>
</html>
```

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

## Available Functions

### [WebViewerServer](#webviewerserver)

### [getPDF](#webviewerservergetpdf)

### [getThumb](#webviewerservergetthumb)

#### `WebViewerServer`

Constructs a server object to communicate with WebViewer Server.

**Parameters**

| Name        | Type   | Description                                     |
| ----------- | ------ | ----------------------------------------------- |
| `options`   | object | An object containing options for the server.    |
| `serverUrl` | string | The address to your WebViewer Server. Required. |

**Returns**

The server object containing all callable functions for the Extended API wrapper.

**Example**

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

```js
const server = WebViewerServer({
  serverUrl: 'http://pdftron.com/myserver'
});
```

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

#### `WebViewerServer.getPDF`

Generates a PDF on the server from the passed URL. Returns a link to the completed PDF.

**Parameters**

| Name            | Type     | Description                                                                                                                                      |
| --------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `options`       | object   | An object containing options for the getPdfFromUrl call. The following are possible arguments:                                                   |
| `uri`           | string   | The uri of the document to generate a PDF from. Overwritten if the `file` argument is passed.                                                    |
| `file`          | object   | A file object for a document to generate a PDF from. Overwrites the `uri` argument if passed.                                                    |
| `pdfa`          | boolean  | If set to true, conversions will be done according to the PDFA format. This feature is only available when using the `uri` argument.             |
| `linearize`     | boolean  | If set to true, the file returned will be linearized.                                                                                            |
| `xfdf`          | string   | Can be set to XFDF that should be merged with the file. Expects UTF-8 encoded XFDF data as a string.                                             |
| `customHeaders` | object   | The custom headers will be used when the server fetches the document requested through the uri argument. They should be passed as a JSON object. |
| `extension`     | string   | The format of the document passed. Only required if the `uri` passed does not have the correct document extension.                               |
| `cacheKey`      | string   | The cacheKey to lock the cache to for this document. If not passed, caching is handled through normal mechanisms.                                |
| `onProgress`    | function | A callback function that returns current progress on the job.                                                                                    |

**Returns**

A promise which resolves to the completed URL for the PDF or rejects with an error.

**Example**

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

```js
function onprog(data) {
  console.log(data);
  // will print current progress
  // { type: 'fetch' or 'upload', loaded: current progress, total: 'total'}
}
server.getPDF({
  uri: 'http://pdftron.com/sample.docx,
  extension: 'docx',
  onProgress: onprog,
}).then(uri => {
  console.log(uri);
  // do something with file link
}).then(e => {
  console.log(e);
});
// now we do the same, except with a file directly on the local system
// get file from input element
const selectedFile = document.getElementById('input').files[0];
server.getPDF({
  file: selectedFile
  onProgress: onprog,
}).then(uri => {
  console.log(uri);
  // do something with file link
}).catch(e => {
  console.log(e);
});
```

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

#### `WebViewerServer.getThumb`

Generates a thumb (image render) of a PDF on the server from the passed URL or file object.

**Parameters**

| Name            | Type     | Description                                                                                                                                      |
| --------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `options*`      | object   | An object containing options for the getPdfFromUrl call. The following are possible arguments:                                                   |
| `uri`           | string   | The uri of the document to generate a PDF from. Overwritten if the `file` argument is passed.                                                    |
| `file`          | object   | A file object for a document to generate a PDF from. Overwrites the `uri` argument if passed.                                                    |
| `onProgress`    | function | A callback function that returns current progress on the job.                                                                                    |
| `customHeaders` | object   | The custom headers will be used when the server fetches the document requested through the uri argument. They should be passed as a JSON object. |
| `cacheKey`      | string   | The cacheKey to lock the cache to for this document. If not passed, caching is handled through normal mechanisms.                                |
| `size`          | string   | The desired size of the rendered image. Allows for `large` (1280p) `medium` (640p) `small` 320p. Defaults to `large`.                            |
| `page`          | number   | The desired page to render of the PDF into an image. Page numbers are indexed starting at 0. Defaults to `0`.                                    |

**Returns**

A promise which resolves to the completed URL for the image or rejects with an error.

**Example**

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

```js
function onprog(data) {
  console.log(data);
  // will print current progress
  // { type: 'fetch' or 'upload', loaded: current progress, total: 'total'}
}
server.getThumb({
  uri: 'http://pdftron.com/sample.docx,
  extension: 'docx',
  onProgress: onprog,
}).then(uri => {
  console.log(uri);
  // do something with file link
}).then(e => {
  console.log(e);
});
// now we do the same, except with a file directly on the local system
// get file from input element
const selectedFile = document.getElementById('input').files[0];
server.getThumb({
  file: selectedFile
  onProgress: onprog,
}).then(function(uri) {
  console.log(uri);
  // do something with file link
}).catch(function(e) {
  console.log(e);
});
```

{% 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/web/webviewer-server/wv-server-wrapper.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.
