admin管理员组

文章数量:1296505

I am doing a function to auto print the pdf file, the file is returned from the server. It is currently showing a print window, but I want the file to be printed on the printer at all times without have to press the print button.

current:

I read a lot of articles on stackoverflow, and other pages but it's failed.

Please help me! Thanks alot

I am doing a function to auto print the pdf file, the file is returned from the server. It is currently showing a print window, but I want the file to be printed on the printer at all times without have to press the print button.

current:

I read a lot of articles on stackoverflow, and other pages but it's failed.

Please help me! Thanks alot

Share Improve this question edited Jan 30, 2019 at 15:57 Richard Parnaby-King 14.9k11 gold badges73 silver badges130 bronze badges asked Oct 12, 2018 at 4:53 Hoang VinhHoang Vinh 2031 gold badge3 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

I have found the solution to the problem

In Chrome:

  • step 1:

config run chrome silent printing on mode --kiosk-printing edit target on chrome shortcut properties Ex:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk-printing "http://localhost:8080/this"

  • step 2:

code

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;

In Firefox:

  • step1: config printing silent

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

  • step 2: code

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

本文标签: Automatic print pdf file on chrome or firefox (both lastest version) using javascriptStack Overflow