【问题标题】:ng2-pdfjs-viewer Internet Explorer 11 unexpected server response (500) while retrieving PDFng2-pdfjs-viewer Internet Explorer 11 在检索 PDF 时出现意外的服务器响应 (500)
【发布时间】:2020-02-06 02:55:49
【问题描述】:

我正在使用 ng2-pdfjs-viewer 来显示用户上传到我的服务器的 PDF。每次用户在他们的视图中单击该文件时,该文件都会从服务器检索并制作成一个 blob 并提供给 ng2-pdfjs-viewer 以显示在 externalWindow 中。这适用于除 IE11 之外的所有浏览器。

起初它在 IE 上运行良好,但如果我多次关闭并打开同一个文件,过一会儿 pdf 查看器会给我一个“在检索 PDF 时出现意外的服务器响应 (500) 'blob:B04FA5CB-1012-4CBC -8DFB-59C4CE02C34A'"。如果我用 IE 打开网站的第二个实例,也会发生这种情况。当它开始出现此错误时,必须关闭整个浏览器,然后我必须返回该网站并重试 - 然后它再次工作。

我对服务器的所有请求都顺利通过,我与 Fiddler 进行了核对。唯一提供给查看器的是 blob,所以我不明白它在哪里得到了意外的服务器响应。一切都可以在其他所有浏览器上完美运行。

如果没有 pdf 查看器,则在所有浏览器上都可以毫无问题地检索文件,并且可以在 IE 上使用 msSaveOrOpenBlob 打开它们。 pdf查看器似乎造成了麻烦。

<!--x.component.html code-->
<ng2-pdfjs-viewer #pdfViewer style="width: 800px; height: 400px"
  [externalWindow]="true"
  [downloadFileName]="'document.pdf'"
  [openFile]="false"
  [viewBookmark]="false"
  [download]="true">
</ng2-pdfjs-viewer>

//x.component.ts code

@ViewChild('pdfViewer', {static: false}) pdfViewer;

openDocument(doc: Document) {

    this.storageService.fetchDocument(doc).subscribe(
      res => {
        let type: string = res['type'];
        let file: string = res['file'];
        var promise = this.uploadService.decodeFromBase64(file);
        promise.then((result:string)=> {
          var byteArray = [];
          for (let i = 0; i < result.length; i++) {
            byteArray.push(result.charCodeAt(i));
          }
          const blob = new Blob([new Uint8Array(byteArray)], {type: type});
          var fileURL = URL.createObjectURL(blob);
          if (type == "application/pdf") {
              this.pdfViewer.pdfSrc = fileURL; 
              this.pdfViewer.refresh();
          }
          else {
              //...
          }
          })
      }
    }

【问题讨论】:

    标签: internet-explorer internet-explorer-11 pdfjs ng2-pdfjs-viewer


    【解决方案1】:

    我从另一个 pdfjs-viewer 文档中找到了这一信息,看起来你的 ng2-pdfjs-viewer 也有类似的问题。

    快速隐藏和重新显示 PDF(反之亦然)会导致错误。这是因为大部分 pdf.js 都是异步工作的。初始化小部件需要一些时间。如果它在初始化时被破坏,你就会遇到问题。如果它在早期实例仍在被销毁时被初始化,也会发生同样的情况。

    将 PDF 放在选项卡中经常会导致此问题。在选项卡之间切换通常意味着隐藏其中一个选项卡的内容。同时显示新标签的内容。我在使用@angular/material 时观察到了这一点。解决方案是隐藏第一个选项卡并在超时后显示新选项卡

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 2019-11-14
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多