Chrome 77 Not Auto-Printing PDFs

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!


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