Webviewer - Custom headers on initial load

442 views
Skip to first unread message

srinivasan Bose

unread,
Jun 13, 2016, 12:36:40 PM6/13/16
to PDFTron WebViewer
Hi,

Iam using webviewer v2.2.0. Inorder to render pdf document.

i need to pass custom authorization header on initial load. I need to attach Authorization header which contains access token in the "initialDoc" property of webviewer intialisation. Is it possible to attach custom headers on webviewer initialisation code itself? 

I can see code like below, where customheaders can be set for 

this.webViewer.loadDocument(repUrl,{customHeaders:{
            'Authorization': 'Bearer ********'
}});

Also how to refresh Annotations data when user clicks on a button?



Matt Parizeau

unread,
Jun 13, 2016, 2:26:52 PM6/13/16
to PDFTron WebViewer
It currently isn't possible to set custom headers with initialDoc, but as a workaround you can remove the initialDoc from your options and then listen to the ready event and call loadDocument there. For example:

$(viewerElement).on('ready', function(event) {
  myWebViewer
.loadDocument('my/initial/doc.pdf', {
      customHeaders
: {
         
Authorization: '...'
     
}
 
});
});

Matt Parizeau
Software Developer
PDFTron Systems Inc.

srinivasan Bose

unread,
Jun 14, 2016, 12:58:48 PM6/14/16
to PDFTron WebViewer
Thank for the reply. 

To my another question above, is there any method available in webviewer to clear / refresh the annotations in webviewer? Also how can we destroy and re-create webviewer instance?

Matt Parizeau

unread,
Jun 15, 2016, 3:40:53 PM6/15/16
to PDFTron WebViewer
Annotations won't be redrawn after importing or programmatically modifying them so you'll need to call drawAnnotations or drawAnnotationsFromList to refresh the view. For example:

annotManager.drawAnnotationsFromList(annotManager.importAnnotations(myXfdf));

If you want to delete all the annotations you can call annotManager.deleteAnnotations(annotManager.getAnnotationsList());

To destroy and recreate the WebViewer instance you can refer to the offline library sample's index.html file which does this. look at the loadViewer function and you'll see it just empties the viewer element (removing the old iframe) and then instantiates a new WebViewer object.

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