Pass headers to PDF Viewer

Hello!

I have the same problem as in this thread  How to Pass Headers With PDF Viewer | Angular - EJ 2 Forums | Syncfusion. I have tried the solution proposed there, but since it overrides the global configuration I am having issues with the other requests that are being made.

Is there a different solution to modify only the necessary requests for the PDF Viewer?

Thank you!



1 Reply

DM Dhivyabharathi Mohan Syncfusion Team November 4, 2021 05:47 AM UTC

Hi Ana, 
 
Thank you for contacting Syncfusion support. 
 
We can include the Authorization token in the PDF Viewer AJAX request using the ajaxRequest headers properties available in AjaxRequestSettings and it will be included in every AJAX request send from PDF Viewer. Please refer to the below documentation and code snippet. 
 
 
Code Snippet: 
 
<ejs-pdfviewer ref="pdfViewer_instance" id="pdfviewer" :serviceUrl="serviceUrl" :documentPath="document" :created="created"></ejs-pdfviewer>   
 
 
  methods: { 
      created(args){ 
          var viewer = document.getElementById('pdfviewer').ej2_instances[0]; 
          viewer.ajaxRequestSettings.ajaxHeaders = [{ headerName:'Authorization',headerValue:'Bearer 64565dfgfdsjweiuvbiuyhiueygf'}]; 
      } 
  }, 
 
 
And you can send the parameter to the specific web action method on the server-side using ajaxRequestInitiate API. Please refer to the below code snippet and documentation. 
 
Code Snippet: 
 
<ejs-pdfviewer ref="pdfViewer_instance" id="pdfviewer" :serviceUrl="serviceUrl" :documentPath="document" :ajaxRequestInitiate = ajaxInitiate></ejs-pdfviewer> 
 
   return { 
   serviceUrl: 'http://localhost:55767/pdfviewer', 
   ajaxInitiate: function (args) { 
        if (args.JsonData.action == "Load") { 
              args.JsonData["title"] = "PDF Viewer";   
              var pdfviewer = document.getElementById('pdfviewer').ej2_instances[0];      
              pdfviewer.setJsonData(args.JsonData);   
  }  
  },   
 
 
 
 
Kindly try this and let us know if you have any concerns about this. 
 
Regards, 
Dhivya. 


Loader.
Up arrow icon