Custom headers in document web request

Skip to first unread message

Peter Znameroski

Dec 5, 2013, 7:55:24 PM12/5/13

I am working on a web app that has a JS client and a server hosted on Tomcat 7 instance. In the client, we instantiate a WebViewer instance and set the "initialDoc" option to a URL that points to a document on our server. However, our server requires custom HTTP request headers for authentication. Is there a way to configure WebViewer to include customer headers when making its request to the "initialDoc" URL to get the XOD document?


P.S. When initializing our application client, we setup jQuery's ajax settings using "$.ajaxSetup" to include our custom headers. That way all ajax requests made by our client include our custom headers by default. If possible, is there anyway we could have WebViewer's jQuery instance inherit these settings so that our custom headers are included in ajax requests made by the WebViewer as well? That would be more ideal than manually setting the custom headers that we want WebViewer to include with the request to our server to get the XOD document.

Matt Parizeau

Dec 6, 2013, 2:13:24 PM12/6/13
Hi Peter,

WebViewer is actually using XMLHttpRequest directly for requests to the XOD document so using jQuery's ajaxSetup function won't work.  Instead what I've done is created a build for you that includes a SetCustomHeaders function on the PartRetriever object.  You can download the build here:

To use the function you would modify ReaderControl.js, specifically the loadDocument function and after partRetriever is created you would call the function, for example like this:
'mycustomheader': 'hello',
'pdftron': 'webviewer'

Note that there are a couple places where ReaderControl code does use $.ajax (e.g. testing for byte range support, loading annotations) so if you wanted to hook into that then to get WebViewer's jQuery instance you could have something like this:
var webviewer$ = $('iframe')[0].contentWindow.$

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