【问题标题】:Print PDF Report in IE 11在 IE 11 中打印 PDF 报告
【发布时间】:2018-11-14 01:58:43
【问题描述】:

正如图块所示,我正在尝试专门在 IE 11 上打印 PDF 报告。下面的 sn-p 代码可以在 chrome 中运行,但是当涉及 IE11 时,一切都变得松散了;没有任何效果。为了给你一个背景,我正在开发 Angular 5 报告应用程序。在这里,用户可以查看、下载和打印报告。除了在 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();

感谢任何输入。

【问题讨论】:

  • 如果没有要调试的 URL,则无法找到确切的问题。不过要尝试一件事。使用其他 iframe 变量名称作为关键字。可能是 IE 搞砸了这种歧义,Chrome 处理得很好。
  • 感谢 Anand 的意见,遗憾的是没有帮助。
  • 这方面有什么更新吗?
  • 您必须为社区托管一个测试页面以进行调试和帮助。
  • 这个问题有什么更新吗??

标签: angular typescript internet-explorer-11


【解决方案1】:

我能够在 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();
   }); 
  };

通过这个 hack,它可以在最新的 IE 上运行

【讨论】:

  • @Ramesh_D 是的,它确实有效。此代码正在生产中。
  • 对于 ie11,我们无法在“iframe.src”中设置 blob 数据 uri。 (根据我的研究)。此代码适用于最新的所有浏览器。但不在 ie11 上。
猜你喜欢
  • 2013-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-26
  • 2014-10-16
  • 2014-03-22
相关资源
最近更新 更多