我正在尝试使用arraybuffer或blob以角度6打印pdf,但是在打印/打开标签页时显示空白的pdf屏幕。
printInvoice(invoiceCode: string): Observable<ArrayBuffer> {
return this.http.get<ArrayBuffer>(this.API_DOMAIN + `/api/v1/data/invoice/show?invoiceCodes=${invoiceCode}`, {responseType: 'arraybuffer' as 'json'})
}
printInvoice(invoiceCode: string) {
this.dataService.printInvoice(invoiceCode).subscribe(response => {
// print file
console.log(response);
var blob = new Blob([response], { type: "application/pdf" });
const blobUrl = URL.createObjectURL(blob);
const iframe = document.createElement("iframe");
iframe.style.display = "none";
iframe.src = blobUrl;
document.body.appendChild(iframe);
iframe.contentWindow.print();
});
}