Some test text!

Cross origin workerskeyboard_arrow_down

Cross origin workers

In some situations you may want to place the large WebViewer worker files on a CDN or some other external server. It's possible to put the entire WebViewer lib folder on another domain however this has some downsides, so only moving the worker files is often a good compromise.

We provide a few APIs to help accomplish this, setLocalWorkerPath and setWorkerPath.

linkSetting Remote Workers

The first step is to copy the worker files and their resources to your external server. Once you download WebViewer, find the following three folders:

  • lib/core/pdf
  • lib/core/office
  • lib/core/external

These are the three folders you need to copy to your CDN or other external server. Make sure they all live in the same directory (the name of the outer directory doesn't matter).

Now you need to tell WebViewer where these folders live. To do this, pass an accessible, absolute path to your folder into the setWorkerPath function.

Add the following code to the top of your config file.

// config.js


Make sure the path you pass in contains all three folders mentioned above, and that they are publicly accessible.

linkSetting Local Workers

In order for us to load these workers from an external domain, we need to use local workers that load the external workers. This is because remote workers cannot be directly loaded from the browser because of security restrictions.

WebViewer needs to know where these local workers exist, and we can use the setLocalWorkerPath API to help it find them.

The path that you pass to setLocalWorkerPath must be local, and is relative to the index file of the UI, which is usually lib/ui/index.html. The path must point to the folder that contains CORSWorker.js and CoreWorker.js, which in most cases is lib/core.

Add the following code underneith the code you added above (in your config file).

// config.js


// Relative to the ui's index.html file

// Or you can pass an absolute path
// CoreControls.setLocalWorkerPath('/public/lib/core');

That's it! Your worker files will now be loaded from your CDN or external server.


If you receive cross origin errors accessing the worker files on the other domain then make sure that you have the Access-Control-Allow-Origin header on these resources, otherwise they won't be able to be loaded from the other domain.

Get the answers you need: Support


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.