【发布时间】: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