Hello, I am working on a project which is generates invoice using php & html. i want to print that invoice directly to default printer using php. Seems printer_write function prints only source code & not the output view. So i created invoice into PDF using FPDF. Still i cant able to print PDF file using printer_write function. Any suggestions? My sample code: $pHandle = fopen("files/sample.pdf", "r"); $handle = printer_open("HP LaserJet 1020"); printer_set_option($handle, PRINTER_MODE, "RAW"); printer_write($handle,$pHandle); printer_close($handle);
Second option is this. at the very end of your HTML page, put this code: <script type="text/javascript"> window.print(); </script> This is recommended by some, argument being that the printing starts only after the page is completely loaded... However, the onload attribute inside <body> gets executed only when the page is completely loaded... So pretty much same thing. https://www.w3schools.com/tags/ev_onload.asp