Multiple PDF print with JavaScript

Viewed 12

I have an access to the website, where I can download a PDF file. I need to click on each button, after will pop up a window with the PDF file and I can print out manually.

I try to send all of the PDF file to the printer directly. I use KIOSK mode with chrome, so I not get the print dialog window.

My only problem is, when I open the URL in new window with javascript and print it out, I get just the blank paper, becasue the page doesnt loaded up. I have few hunder PDF sometimes, so I need to close alsoe the pop up window. But the problem is the delay option not the best. Sometimes the page can load up within 2sec but sometimes take 20sec.

Is there any solution for say to my code, wait till the PDF load up properly?

var printWindow = window.open( 'URL', 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');

printWindow.addEventListener('load', function() {
    if (Boolean(printWindow.chrome)) {
        printWindow.print();
        printWindow.hide();
        setTimeout(function(){
            printWindow.close();
        }, 1500);
    } else {
        printWindow.print();
        printWindow.close();
    }
}, true);
0 Answers
Related