如何在PDFTron Webviewer中添加请求配置,同时使用URL获取文档



我正试图在服务器A上托管的角度应用程序中使用PDFNet/PDFTron WebViewer,我想从服务器B加载PDF文件。为了加载需要验证的pdf文件,服务器B在我的浏览器上设置了一个cookie。因此,我在GET请求中传递withCredentials:true

在使用WebViewer时,我将该URL传递给WebViewer的initialDoc参数,API将返回401状态代码。

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);

我不知道在哪里可以传递请求配置,以便通过身份验证获取该文档。有没有什么方法可以让我用凭据进行HTTP调用来获取PDF文件。提前谢谢。

您需要下载最新版本的WebViewer 2.2.2,其中包括设置凭据的功能。

下载后,您需要将以下代码添加到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;

最新更新