Używam Angular2. Otrzymuję odpowiedź PDF jako BLOB z API zaplecza. Plik PDF wygląda dobrze w elemencie iframe, ale pokazuje tytuł jako "anonimowy". Czy ktoś może podać przewodnik?PDF w elemencie iframe z tytułem "Anonimowy"
kod HTML:
<iframe id="showPDFIframe" allowtransparency="false" title="TestPDF" width="100%" height="800" [attr.src]="dataLocalUrl" type="application/pdf"></iframe>
pdf.component.ts
pdfDownload: any;
protected dataLocalUrl: SafeResourceUrl;
ngOnInit() {
this.requestOptions = this.createRequestOptions();
this.requestOptions.responseType = ResponseContentType.Blob;
this._pdfModelService.showPDF(this.requestOptions)
.subscribe((res) => {
this.pdfDownload = res;
this.dataLocalUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(res));
}, err => {
console.log(err);
})
}
pdfModelService.ts
showPDF(options?: RequestOptions): any {
return this._http.get(this.endpoints.showPDF.uri, options)
.map((res) => {
return new Blob([res], { type: 'application/pdf' })
});
}
Poniżej obrazek 'Anonymous' pokazuje
Uwaga: API backendu podaje bajty, które rzutujemy na BLOB.
Czy możesz pokazać nagłówki odpowiedzi? –