I have an angular2 project with an ASP.Net Web API. I have code to retrieve a file path from my database which goes to a document on my server. I then want to display this d
ANGULAR 5
I had the same problem which I lost few days on that.
Here my answer may help others, which helped to render pdf.
For me even though if i mention as responseType : 'arraybuffer', it was unable to take it.
For that you need to mention as responseType : 'arraybuffer' as 'json'.(Reference)
Working code
service.ts
downloadPDF(): any {
return this._httpClient.get(url, { responseType: 'blob' as 'json' })
.map(res => {
return new Blob([res], { type: 'application/pdf', });
});
}
component.ts
this.myService.downloadPDF().subscribe(
(res) => {
var fileURL = URL.createObjectURL(res);
window.open(fileURL);
}
);
Referred from the below link
https://github.com/angular/angular/issues/18586