【发布时间】:2022-11-28 11:16:30
【问题描述】:
我有一个使用 ng2-pdf-viewer 的页面:
<pdf-viewer [src]="fileToDownload" [render-text]="true" style="display: block;"></pdf-viewer>
有一个节点 API 可以填充该 PDF 并返回一个 URL:
this.httpClient.post(APIURL, JSON.stringify(body), options).subscribe(
result => {
let apiResponse: any = result;
if (apiResponse.success == 1) {
this.showPreviewPDF = true;
let myfileToDownload = sessionStorage.getItem('endPoint') + "downloads/" + apiResponse.file;
this.httpClient.get(myfileToDownload, { responseType: 'arraybuffer' })
.subscribe((file: ArrayBuffer) => {
this.fileToDownload = new Uint8Array(file);
});
}
},
error => {
});
然后我得到 PDF 的流。我可以在控制台网络上完美地看到 PDF,但我无法显示它。
我检查了几个例子,包括改变这个
this.fileToDownload = new Uint8Array(file);
这样
this.fileToDownload = file;
但我仍然无法在屏幕上显示 PDF。如果我将 PDF 指向 Node 外部的文件夹,但不是作为流,它工作正常。
谢谢。
【问题讨论】:
-
嗨,K J。在 Safari 中,当检查“网络”选项卡时,我可以看到 PDF 文档及其完美流式传输。我只是在 pdf-viewer 上显示它时遇到问题。谢谢。
标签: angular