Tôi đang sử dụng Angular2. Tôi nhận được phản hồi PDF dưới dạng BLOB từ API phụ trợ. PDF hiển thị tốt trong khung nội tuyến nhưng nó đang hiển thị tiêu đề là 'ẩn danh'. Ai đó có thể vui lòng hướng dẫn?PDF trong iframe hiển thị tiêu đề là 'Chưa xác định'
mã 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' })
});
}
Xem bên dưới hình ảnh 'Anonymous' đang hiển thị
Lưu ý: API phụ trợ cung cấp các byte mà chúng tôi truyền trong BLOB.
Bạn có thể hiển thị tiêu đề phản hồi của mình không? –