Serve WebViewer from CDN

139 views
Skip to first unread message

Donald Gordon

unread,
Apr 5, 2016, 1:29:18 PM4/5/16
to PDFTron WebViewer

Hi

I'm trying to serve all my static assets from a CDN (https://xyz.cloudfront.net/, while app is at https://subdomain.example.com/).  I'm trying to get WebViewer to load from the CDN.

Cross-iframe call issues mean I need to load ReaderControl.html off the App domain (https://subdomain.example.com/).  I've managed to do this, and have changed all the resource references in ReaderControl.html to point to CDN URLs.

I'm passing


to the PDFTron.WebViewer constructor.  I've modified webviewer.js to not prepend the "path" value to htm5Path.

When I do this, the webviewer pulls some resources from https://subdomain.example.com/WebViewer/: Resources/i18n/translation-en.json, Resources/hand.png, Resources/hand.cur, DecryptWorker.js -- is there some way to get *all* asset requests to use the path passed to the PDFTron.WebViewer constructor?

Thanks

Donald

Matt Parizeau

unread,
Apr 6, 2016, 8:33:27 PM4/6/16
to PDFTron WebViewer
Hi Donald,

The base element might be what you're looking for: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

If this that doesn't work then you might just need to update each of locations manually.
translation-en.json: ControlUtils.js, change the resGetPath in the getI18nOptions function
hand.png, hand.cur: Unfortunately I think you'd need to search and replace in CoreControls.js
DecryptWorker.js: call CoreControls.setWorkerPath

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Donald Gordon

unread,
Apr 7, 2016, 12:48:46 PM4/7/16
to PDFTron WebViewer
Thanks Matt.

The base element makes the webviewer load go into an infinite loop of Javascript errors.  I think I'll just cope with those assets being loaded via my app server for now.

Would it be possible to make these asset paths (the .html files) configurable in a later release, and ensure that all other assets including hand.png et al and the translation json files are loaded from the path passed into the PDFTron.Viewer constructor?

I've managed to back out all my patches to webviewer that I thought I needed, except for the change to WebViewer.js that allows me to pass an absolute html5Path and html5Mobile.  I'm happy regenerating ReaderControl.html with new absolute paths -- I can do that with sed -- but would prefer to avoid maintaining a patch set against your Javascript code.

Regards

Donald

Matt Parizeau

unread,
Apr 8, 2016, 3:52:35 PM4/8/16
to PDFTron WebViewer
Hi Donald,

Thanks for the suggestion. We'll add it to our list of things to consider for a future release.

Matt Parizeau
Software Developer
PDFTron Systems Inc.
Reply all
Reply to author
Forward
0 new messages