Some test text!

menu
search

Open a document

There are a few ways to open a document such as from a URL, a blob, the filesystem, or base64 data. Additionally, there are loading options to help WebViewer determine the type of the file being loaded.

Loading options

When loading a document, 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.

linkThe extension option

You can use the extension option to explicitly tell WebViewer what type of file it is, for example, extension: 'docx' or extension: 'png'. Sometimes a URL might not contain an extension or you might be loading a blob so there is no URL. By default WebViewer will assume it's a PDF file but that might not be correct.

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

You can also pass extension as an option to the loadDocument method like this:

WebViewer(...)
  .then(function(instance) {

    instance.loadDocument('http://<documentserver>/FileDownload?param1=foo', {
      extension: 'docx'
    });

    //...
  });

linkThe 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.

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

/// or 

WebViewer(...)
  .then(function(instance) {

    instance.loadDocument('http://<documentserver>/FileDownload?param1=foo', {
      filename: 'report.docx'
    });

    //...
  });

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.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn More
close