Angular 6-使用arraybuffer打印pdf显示空白屏幕

时间:2018-10-08 19:51:09

标签: angular

我正在尝试使用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();
    });
  }

0 个答案:

没有答案
相关问题