【发布时间】:2019-09-11 17:56:23
【问题描述】:
我想使用打字稿打印 blob (pdf)。我尝试了下面的代码,它适用于 Chrome,但不适用于 Edge。
代码 1(适用于 Chrome,但在 Edge 中打印时显示空白)-
const fileURL = URL.createObjectURL(blob);
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = fileURL;
iframe.name = fileName;
document.body.appendChild(iframe);
iframe.contentWindow.print();
代码 2(适用于 Chrome,但 contentWindow 为空,因此会为 contentWindow.document 引发错误)-
const fileURL = URL.createObjectURL(blob);
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = fileURL;
iframe.name = fileName;
document.body.appendChild(iframe);
document.getElementsByTagName('iframe')[0].contentWindow.document.execCommand('print', false, null)
我看到了很多问题,但没有一个问题得到解答。我正在使用 Angular 6,所以有没有直接的方法来实现这个或任何可以实现它的库。
【问题讨论】:
标签: angular typescript internet-explorer iframe blob