Some test text!

menu

Creating Office documents using JavaScript

If you have a URL for a document, you can pass it to the WebViewer constructor or loadDocument function to open it.

Another more advanced option is to use createDocument which does not require WebViewer to be initalized.

linkWebViewer constructor

Load the office document with the WebViewer constructor and it will load with the Viewer.

WebViewer({
  ...,
  initialDoc: 'https://myserver.com/myfile.docx',
}, document.getElementById('viewer'));

Display & view documents using JavaScript
Full sample code shows how to call WebViewer constructor to instantiate and load document. You can load local/remote files of your choice.

linkLoad document

Load the office document with the load document method after WebViewer is initalized.

WebViewer(...)
  .then(instance => {
    instance.loadDocument('https://myserver.com/myfile.docx', { filename: 'myfile.docx' });
  });

Display & view documents using JavaScript
Full sample code shows how to call WebViewer constructor to instantiate and load document. You can load local/remote files of your choice.

linkAdvanced office loading

Creating an Office document is similar to creating a PDF document except the Office worker needs to be initialized.

With WebViewer 6.0+, the Officer worker will initialize while calling createDocument.

<html>
  <body>
    <script src="../lib/core/CoreControls.js"></script>
    <script>
    (async function() {
      CoreControls.setWorkerPath('../lib/core');

      const licenseKey = 'Insert commercial license key here after purchase';

      // Instantiate a Document object.
      const doc = await CoreControls.createDocument('/path/to/file.docx', { l: licenseKey });
    })()
    </script>
  </body>
</html>

Alternatively, CoreControls is available with the WebViewer instance as well.

WebViewer(...)
  .then(async instance => {
    const licenseKey = 'Insert commercial license key here after purchase';

    // Instantiate a Document object.
    const doc = await instance.CoreControls.createDocument('/path/to/file.docx', { l: licenseKey });
  });

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