Chrome 77 Not Auto-Printing PDFs

泄露秘密 提交于 2021-02-04 17:46:22

问题


Chrome 77 has stopped respecting the print() embedded JS in PDFs to initiate/open the print dialog after a PDF has been loaded.

For example, open the below file in Firefox, Chrome 76, or in Acrobat and you'll see the print dialog appear. In Chrome 77 it is no longer appearing. Specifically, in my case and on three other computers I tested this on, version 77.0.3865.75.

https://cdn.dealrcloud.com/assets/test/Invoice-1003.pdf

Is this a new setting we can adjust/modify or is this a permanent breaking change that will prevent us from auto-triggering a print dialog for Chrome clients?


回答1:


This was deliberately removed.

Allow print() only in response to a user gesture

https://pdfium.googlesource.com/pdfium.git/+/2021804f1b414c97667c03d7ab19daf66f6a19ef

The issue was that the embedded JavaScript in PDF files did not respect the Content-Security-Policy of the embedding page. https://crbug.com/968914




回答2:


Ok, guys. I came across the same problem having auto print pdf feature not working on several laptops. This feature is very critical on several of our projects, so I thought this workaround for Chrome 77 might be very helpful for community as well:

var loadPDFAndPrint = function (id, url) {
    $("#"+id).remove();
    $("<iframe id='"+id+"' name='"+id+"'>")
        .hide()
        .attr("src", url)
        .appendTo("body");
    $("#"+id).on("load", function(){
        function getChromeVersion () {
            var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); 
            return raw ? parseInt(raw[2], 10) : false;
        }
        if (getChromeVersion() >= 77) {
            window.frames[id].focus();
            window.frames[id].print();
        }
    })
}

This code requires jQuery, but you can easily adapt it to any js flavour you want.

Cheers!




回答3:


I commented here about this issue this is where it all started

https://bugs.chromium.org/p/chromium/issues/detail?id=968914




回答4:


Chrome direct printing has been replaced by the WebApp Hardware Bridge. The git repository is here: https://github.com/imTigger/webapp-hardware-bridge

I downloaded last week and am currently testing.



来源:https://stackoverflow.com/questions/57895126/chrome-77-not-auto-printing-pdfs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!