我正在使用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查看器似乎引起了麻烦。
[externalWindow]="true"
[downloadFileName]="'document.pdf'"
[openFile]="false"
[viewBookmark]="false"
[download]="true">
//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 {
//...
}
})
}
}