Print PDF Report in IE 11

时间:2018-06-04 17:07:15

标签: angular typescript internet-explorer-11

As the tile suggest, I am trying to print a PDF report specifically on IE 11. The following snippet of code works will in chrome, but when it come to IE11, all hell breaks loose; nothing works. To give you a background, I am developing Angular 5 reporting application. Here the user can view, download and print the report. I was able to achieve all the above functionalities except for printing on IE 11!

      const iframe = document.createElement('iframe');
      iframe.style.display = 'none';
      iframe.src = window.URL.createObjectURL(new Blob([result], { type: 'application/pdf' }));
      document.body.appendChild(iframe);
      iframe.contentWindow.print();

Any input is appreciated.

1 个答案:

答案 0 :(得分:0)

我能够在IE上打印,这是我学到的一个小技巧,它可以正常工作。

  const iframe = document.createElement('iframe');
  iframe.style.display = 'none';
  iframe.src = window.URL.createObjectURL(new Blob([result], { type: 'application/pdf' }));
  document.body.appendChild(iframe);
  iframe.load = () => {
  setTimeout(() => {
  iframe.focus();
  iframe.contentWindow.print();
   }); 
  };

通过此黑客,它可以在最新的IE上运行