在IE 11中打印PDF报告

问题描述:

正如图块所建议的那样,我正在尝试专门在IE 11上打印PDF报告.什么都行不通.为了给您提供背景知识,我正在开发Angular 5报告应用程序.用户可以在此处查看,下载和打印报告.除了在IE 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();

感谢您的任何投入.

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

I was able to get print on IE, this is a slight hack I learned, it works.

  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上运行

with this hack, it worked on the latest IE