'Displaying ng2-pdf-viewer PDF from stream
I have a page that uses ng2-pdf-viewer:
<pdf-viewer [src]="fileToDownload" [render-text]="true" style="display: block;"></pdf-viewer>
There is a Node API that populates that PDF and returns a 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 => {
});
Then I get the stream for the PDF. I can see the PDF perfectly on the console network, but Im not able to display it.
I checked several examples, including changing this
this.fileToDownload = new Uint8Array(file);
by this
this.fileToDownload = file;
But I still cannot display the PDF on screen. It works fine if I point the PDF to a folder outside Node, but not as a stream.
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
