【问题标题】:How to add request config in PDFTron Webviewer while fetching a doc using URL?使用 URL 获取文档时如何在 PDFTron Webviewer 中添加请求配置?
【发布时间】:2017-02-08 10:40:29
【问题描述】:

我正在尝试在服务器 A 上托管的 Angular 应用程序中使用 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 文件。 提前致谢。

【问题讨论】:

    标签: authentication webview pdftron


    【解决方案1】:

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

    下载后,需要在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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-09
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 1970-01-01
      相关资源
      最近更新 更多