Aman Gupta
Aman Gupta

Reputation: 239

How to add request config in PDFTron Webviewer while fetching a doc using URL?

I'm trying to use PDFNet / PDFTron WebViewer within an angular application which is hosted on server A and I want to load a PDF file from the server B. To load that pdf file authentication is required, the server B set a cookie on my browser. So I pass the withCredentials: true in the GET request.

While using WebViewer I am passing that URL to initialDoc param of WebViewer and the API is returning 401 status code.

var viewerElement = $('#viewer');
var myWebViewer = new PDFTron.WebViewer({
            type: "html5",
            path: "path/to/lib",
            streaming : "true",
            initialDoc: "**Server B URL to load pdf file**",
            documentType : "pdf",
            config: "path/to/config"
        }, viewerElement);

I am not able to understand where can I pass the request configs so that I will be authenticated to fetch that document. Is there any way by which I can make the HTTP call with credentials to get the PDF file. Thanks in advance.

Upvotes: 1

Views: 874

Answers (1)

Ryan
Ryan

Reputation: 2570

You need to download the latest release of WebViewer 2.2.2, which includes the ability to set withCredentials.

After downloading, you would need to add the following code to config.js

var oldLoadDocument = ReaderControl.prototype.loadDocument;
var loadDocument = function(doc, options) {
  options.withCredentials = true;
  return oldLoadDocument.call(this, doc, options);
}
ReaderControl.prototype.loadDocument = loadDocument;

Upvotes: 0

Related Questions