Open the printer dialog box for the PDF file. Automatically

I know that there are ways to print a PDF file on a network printer located on the same network as the server, but this does not help me, since the server is remote. In my situation, the user clicks the link to “print labels”, which then generates and displays a PDF file formatted for them. I am currently “transferring” the output of the file to the browser, so Adobe Reader automatically opens it using the following code:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Content-type: application/pdf"); header('Content-Disposition: attachment; filename="labels.pdf"'); readfile($ServerPathToFile); 

Is there anything else I can add to this code that will automatically launch the print dialog to open so that they only press print? In this case, Google CloudPrint is not an option, as well as other things that require a “special setup” at the end of the user ... as this will be used by different users.

+4
source share
2 answers

You can output the PDF to a child window ( <iframe> ) in the same domain, and then call window.print() in that window.

 <p>Don't forget to print your document!</p> <iframe src="/path/to/your/pdfgenerator.php" id="mypdf"></iframe> <script> function printIframe(id) { var iframe = document.frames ? document.frames[id] : document.getElementById(id); var ifWin = iframe.contentWindow || iframe; iframe.focus(); ifWin.printPage(); return false; } </script> 

On the iframe page, add the following:

 function printPage() { print(); } 
+3
source

I just finished a project that printed shortcuts from a browser to a printer to print labels on the web. You must do this using javascript. I used the Dymo SDK and created my own user interface for automatically printing name tags after a person registered at the kiosk. Sign icons awaited them at the main check-in station.

The srcipt that I used was to be installed only on the server, and everyone else on the network could print to the network printer.

0
source

All Articles