Some test text!

Loading...
Guides
Usage

Optimize / customize WebViewer Server usage

Normal Usage

WebViewer Server is designed to work hand-in-hand with the WebViewer client in order to seamlessly optimize the viewing experience. Once the server is running, simply supply the webviewerServerURL argument to WebViewer upon startup:

options.webviewerServerURL = 'http://<docker_address>'
WebViewer(options, viewerElement);
options.pdftronServer = 'http://<docker_address>'
WebViewer(options, viewerElement);

This will ensure an optimal client experience on any of your target platforms, optimizing the delivery method as required.

Caching and Performance

In order to handle requests as quickly as possible with minimal server load, WebViewer Server caches intermediate data opportunistically. For example, this might include includes caching parsed PDF content in memory for quick re-renders of the same doc, caching conversion results, fetched data, and render tiles, if used.

It will also batch requests together in order to minimize cpu-heavy operations like conversions -- if users Alice and Bob try to view the same Word document at the same time, then only one conversion to PDF will ever take place, and the will be broadcast to both users. For documents under high contention (as might happen when sharing a doc for review), the performance benefit can be tremendous.

In order for this caching and batching to work correctly, the server requires that incoming URLs map to documents in a one-to-one manner, including query parameters. If Alice and Bob access the same document but via different URLs, then the server will assume they are different documents and end up doing more work than is required. In order to ensure the cache is working as intended, it may be necessary to move unique URL query parameters (access tokens and time stamps, for example) into the request headers instead.

Controlling the Document Cache with CacheKey

We also offer method of controlling caching on the WebViewer Server. When requesting documents you can pass a cacheKey to the load document call. This will cause the document requested to be cached on the cacheKey you have provided. If a request is ever made to this cacheKey, the document first cached under that key will be returned.

WebViewer(...)
  .then(instance => {
    const options = {
      cacheKey: "unique_id_entry123",
    };
    const url = 'http://<documentserver>/FileDownload?param1=abcd&fetchid=dcba';
    instance.loadDocument(url, options);
  });
});

Server authentication

When a document URL is provided to WebViewer, that URL will now be fetched by the docker server instead of the browser. If authorization information needs to be provided to the server providing the document, this can be done using the customHeaders option when creating a document.

You can also provide the filename option to ensure that the server knows what type of file you are attempting to view (in case it is not clear from the URL).

WebViewer(...)
  .then(instance => {
    const options = {
      customHeaders: { Cookie: "MYAUTHTOKEN=BF6CF50AB90C4025" },
      filename: "Document.pdf"
    };
    const url = 'http://<documentserver>/FileDownload?param1=abcd&fetchid=dcba';
    instance.loadDocument(url, options);
  });
});

When the docker server makes a request to fetch http://<documentserver>/FileDownload?param1=abcd&fetchid=dcba, the http request will include the values in options.customHeaders.

Custom Query Parameters

It is also possible to append a query parameter onto every request made to and from WebViewer Server. This can be used as a form of authentication or to handle some other system. To do so, call loadDocument with your custom query parameters like so:

instance.loadDocument('http://pdftron.com/mydocument.pdf', { 
  webViewerServerCustomQueryParameters: { param1: 'param1data', param2: 'param2data'}
});

Now every link will have param1 and param2 appended to it as a query parameter.

Extended API

For most use cases no extra interaction with the server is required, beyond what is mentioned in the previous section. For special cases, these endpoints can be used to further optimize your application, or tailor it to your own particular use case

PreloadURL

Preload a document into WebViewer server prior to actually viewing it.

Params

Example

For example, to pre-fetch http://domain/document.pdf, make a GET request to http://<docker_address>/blackbox/PreloadURL?url=http%3A%2F%2Fdomain%2Fdocument.pdf

Returns

Returns code 200 once the information has been received by the server. The response is asynchronous -- the return does not indicate that all preload work has been completed.

HealthCheck

Check whether your server is over capacity. Uses a system of queue timing checks to determine if the average window of queue times has exceeded 300ms. When this API fails, WebViewer will attempt to swap to another server if connected to WebViewer Server.

Access Points

  • myserver/blackbox/HealthCheck
  • myserver/blackbox/health

Example

For example, to check the state of your work queue, access http://domain/document.pdf, make a GET request to http://<docker_address>/blackbox/HealthCheck

Returns

  • response code 200 - the server is up, and capable of serving requests at interactive speeds.
  • response code 503 - the server is up, but over capacity.
  • any other response - outside the scope of this endpoint.

Life Check

Check whether your server is at a point where it is unlikely to function. This uses the same mechanism as the HealthCheck, but expects an average window of queue times to be greater than 1 second. Requires 1.5.7 or greater.

Access Points

  • myserver/blackbox/alive

Example

To check if your server is still responsive enough to be functional, make a GET request to http://<docker_address>/blackbox/alive

Returns

  • response code 200 - the server is up, and capable of serving requests at interactive speeds.
  • response code 500 - the server is no longer functioning properly.

GetSupportedFormats

Get the currently supported formats by the server. Will return the formats in a JSON array. Any formats not listed by this API will be rejected by the server. Requires 1.5.7 or greater.

Access Points

  • myserver/blackbox/GetSupportedFormats

Example

curl localhost:8090/blackbox/GetSupportedFormats

Returns

  • response code 200 - will return the allowed server formats in a JSON array

GetPDF

GET request to convert a document to PDF format, and return the result. This functionality is not part of the default functionality of WebViewer server and must be licensed separately. Please talk to our sales team for more details.

Access Points

  • myserver/blackbox/GetPDF

Params

fmt

The return format, if set to "data", will redirect to the actual pdf document, otherwise will return json data in the form [{"uri":"<location of the pdf>"}]

xfdf

The raw annotation data you wish to merge in with the document when performing the GetPDF job. This is expected in the XFDF format. Requires a POST request instead of a GET request.

PDFTron-Custom

A HTTP header which can be set with a JSON object containing custom headers like so:

request.setRequestHeader('PDFTron-Custom', JSON.stringify({
    Cookie: "AUTHCOOKIE=123;OTHERCOOKIE=124", myHeader:"test"
  }));

The custom headers will be used when the server fetches the document requested through the uri argument.

cacheKey

The key to cache the document against. This will force the server to always return the same cached item corresponding to the cacheKey passed.

Example

To obtain http://domain/document.docx in PDF format, access , make a GET request to http://<docker_address>/blackbox/GetPDF?uri=http%3A%2F%2Fdomain%2Fdocument.docx&fmt=data&ext=docx

To instead obtain a json formated link to the conversion result, make a GET request to http://<docker_address>/blackbox/GetPDF?uri=http%3A%2F%2Fdomain%2Fdocument.docx

Changing the result URL download name

If you wish for the result from GetPDF to be saved with a different name than it has and downloaded directly, set the query parameters on the download link attach=true and dlname to the name you wish to give the file. The example below shows how this would be done:

http://localhost:8090/data/Converted/Fetched/myfile228288ccc.pdf?attach=true&dlname=mynewdocumentname.pdf

Returns

  • If fmt is set to "data", returns the converted PDF data.
  • Otherwise returns a url to the converted result, relative to http://<docker_address>/blackbox/. This result is in json: [{"uri":"<location of the pdf>"}]
  • In the case where this functionality has not been licensed, will return code 403 (forbidden).

GetThumb

Retrieve an image version of a PDF page. Allows the retrieving of files that can be used as thumbnails or previews.

Access Points

  • myserver/blackbox/GetThumb

PDFTron-Custom

A HTTP header which can be set with a JSON object containing custom headers like so:

request.setRequestHeader('PDFTron-Custom', JSON.stringify({
    customHeaders: { Cookie: "AUTHCOOKIE=123"}
  }));

The custom headers will be used when the server fetches the document requested through the uri argument.

Example

const request = new XMLHttpRequest();
  const docUrl = 'https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf';
  const page = 0;
  const size = 'large';
  let url = joinPaths('https://demo.pdftron.com/blackbox/GetThumb?uri=' + encodeURIComponent(docUrl) + "&page=" + page + "&size=" + size);
  request.open('GET', url);
  request.withCredentials = true;
  request.onreadystatechange = () => {
    if (request.readyState === 4) {
      try {
        if (request.status === 200) {
          const data = JSON.parse(request.responseText);
          for (let i = 0; i < data.length; i++) {
            if(data[i].uri){
              ///do something with thumb
            }
          }
        } else {
          //error
        }
      } catch (e) {
        //error
      }
    }
  };

  request.send();

Returns

Returns code 200 if the image render was successful and returns json containing the URI to the image file in the format:

{
  [uri: 'https://pdftron.com/document.pdf']
}

Get the answers you need: Support