Some test text!

menu
WVS API Wrapperkeyboard_arrow_down

WebViewer Server API Wrapper

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.

linkUsage

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

  wvs.getPDF({  url: 'http://192.168.10.56/myfile.pdf' }).then(function (pdfLink) {
      window.open(pdfLink, "theFrame");
  });
</script>

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

linkAvailable Functions

linkWebViewerServer

linkgetPDF

linkgetThumb

linkWebViewerServer

Constructs a server object to communicate with WebViewer Server.

linkParams

linkoptions

An object containing options for the server.

linkserverUrl

The address to your WebViewer Server. Required.

linkExample

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

linkReturns

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

linkWebViewerServer.getPDF

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

linkParams

linkoptions

An object containing options for the getPdfFromUrl call. The following are possible arguments:

linkuri

The url of the document to generate a PDF from. Overwritten if the file argument is passed.

linkfile

A file object for a document to generate a PDF from. Overwrites the uri argument if passed.

linkpdfa

If set to true, conversions will be done according to the PDFA format. This feature is only available when using the uri argument.

linkcustomHeaders

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.

options: {
   customHeaders: {Cookie: 'test=123', MyHeader: '123'}
}
linkextension

The format of the document passed. Only required if the uri passed does not have the correct document extension.

linkcacheKey

The cacheKey to lock the cache to for this document. If not passed, caching is handled through normal mechanisms.

linkonProgress

A callback function that returns current progress on the job.

linkExample

function onprog(data) {
  console.log(data);
  // will print current progress
  // { type: 'fetch' or 'upload', loaded: current progress, total: 'total'}
}

server.getPDF({
  url: '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);
});

linkReturns

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

linkWebViewerServer.getThumb

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

linkParams

linkoptions

An object containing options for the getPdfFromUrl call. The following are possible arguments:

linkuri

The uri of the document to generate a PDF from. Overwritten if the file argument is passed.

linkfile

A file object for a document to generate a PDF from. Overwrites the uri argument if passed.

linkonProgress

A callback function that returns current progress on the job.

linkcustomHeaders

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.

options: {
   customHeaders: {Cookie: 'test=123', MyHeader: '123'}
}
linkcacheKey

The cacheKey to lock the cache to for this document. If not passed, caching is handled through normal mechanisms.

linksize

The desired size of the rendered image. Allows for large (1280p) medium (640p) small 320p. Defaults to large.

linksize

The desired page to render of the PDF into an image. Page numbers are indexed starting at 0. Defaults to 0.

linkExample

function onprog(data) {
  console.log(data);
  // will print current progress
  // { type: 'fetch' or 'upload', loaded: current progress, total: 'total'}
}

server.getThumb({
  url: '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);
});

linkReturns

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

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more
close