【问题标题】:Not detecting afterprint from PDF未检测到 PDF 的余印
【发布时间】:2020-08-21 13:42:36
【问题描述】:

我收到了来自服务器的 PDF,用户经常想要在其中打印而无需真正查看它。我尝试使用onafterprint 事件来关闭窗口,但是,当我以这种方式打开 PDF 时,它似乎不会被触发。如果我改为将 URL 设置为空白以打开一个空页面,它似乎工作得很好。

let url = URL.createObjectURL(blob);
let printWindow = window.open(url);
printWindow.onafterprint = function(){
  console.log("afterprint")
};

【问题讨论】:

    标签: javascript google-chrome pdf printing


    【解决方案1】:

    您的代码不会被执行,因为 pdf 窗口 MIME 类型是“application/pdf”,而不是“text/html”。

    查看此以获取更多详细信息。 https://stackoverflow.com/a/51735450/1141936

    【讨论】:

      猜你喜欢
      • 2022-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 2017-01-07
      • 2018-12-11
      • 2019-11-25
      相关资源
      最近更新 更多