Search code examples
angularsyncfusionpdf-viewer

Syncfusion Angular PDF Viewer Control - Passing Headers Along


We use token-authentication on our endpoints and when viewing a PDF I'd like to use the standard Syncfusion implementation approach but want to know if it's possible to pass headers along with the request. I've ask the question on their forums but I'm aware that feedback can take a bit long.

I see that its possible with their "Uploader control implementation"


Solution

  • We can add Authorization header to the PDF Viewer control’s AJAX request in the sample level. Kindly include the below code in ngOnInit() of TS file,

    ngOnInit(): void {            
        (<any> XMLHttpRequest).prototype.realSend = XMLHttpRequest.prototype.send;
        var newSend = function (vData) {      
            this.setRequestHeader('Authorization', 'Bearer 64565dfgfdsjweiuvbiuyhiueygf');          
            this.realSend(vData);
        };
        XMLHttpRequest.prototype.send = newSend;
    }
    

    The XMLHttpRequest’s method setRequestHeader(), adds custom HTTP headers to the request.

    We have created the sample for the same and shared in the following location, https://www.syncfusion.com/downloads/support/directtrac/general/ze/my-app_Authentication1715968051

    Please find the below KB link for reference, https://www.syncfusion.com/kb/10334/how-to-add-anti-forgery-token-to-the-pdfviewercontrol

    Please try this and let us know if you have any concerns on this.

    Regards, Akshaya