【问题标题】:Automatic print pdf file on chrome or firefox (both lastest version) using javascript使用javascript在chrome或firefox(最新版本)上自动打印pdf文件
【发布时间】:2019-03-17 06:28:32
【问题描述】:

我正在执行自动打印 pdf 文件的功能,该文件是从服务器返回的。 它目前正在显示一个打印窗口,但我希望文件始终在打印机上打印,而不必按下打印按钮。

当前:

我在stackoverflow和其他页面上阅读了很多文章,但都失败了。

请帮帮我! 非常感谢

【问题讨论】:

    标签: javascript google-chrome pdf browser printing


    【解决方案1】:

    我已经找到了问题的解决方案

    在 Chrome 中:

    • 第 1 步:

    config 在 chrome 快捷方式属性上运行 chrome 静默打印模式 --kiosk-printing 编辑目标 例如:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk-printing "http://localhost:8080/this"

    • 第 2 步:

    代码

    var iframe = document.createElement('iframe');
                document.body.appendChild(iframe);
                iframe.style.display = 'none';
                iframe.onload = function() {
                    setTimeout(function() {
                        iframe.focus();
                        iframe.contentWindow.print();
                    }, 0);
                };
                iframe.src = _blobUrl;
    

    在 Firefox 中:

    • 第 1 步:配置静默打印

    转到 about:config create new Boolean preference name="print.always_print_silent" Value=true

    • 第 2 步:代码

      var myWindow = window.open(_blobUrl, '_blank', 'width=800,height=600'); myWindow.focus(); myWindow.print(); myWindow.close();

    【讨论】:

      猜你喜欢
      • 2011-04-03
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-15
      • 2013-04-25
      • 1970-01-01
      • 2014-10-19
      相关资源
      最近更新 更多