I have a php program to generate a bill. I have formatted the bill using css in my program. Now i need to send this data to my default printer once i press the print button. Please help me with the code that sends the data to the printer
Asked
Active
Viewed 6,762 times
2 Answers
1
You can't do that with PHP, but you can use JavaScript fairly easily.
When the user clicks the print button, simply do the following:
window.print();
This will then call the default system print dialog.

BenM
- 52,573
- 26
- 113
- 168
-
If i use window.print(); i'll get the webpage details in the header and footer. I want to ignore it – Vishnu Priyan Rangasamy Nov 21 '13 at 11:43
-
http://stackoverflow.com/questions/1960939/disabling-browser-print-options-headers-footers-margins-from-page – Paul Dixon Nov 21 '13 at 11:45
-
1Unless @Paul Dixon's answer is sufficient, then aside from creating a PDF, you can't do that. – BenM Nov 21 '13 at 11:45
0
$printerName ='';
echo $printerName;
$printer = $printerName;
if($ph = printer_open($printer)) {
printer_start_doc($ph, "Start Doc");
$content = "myfile.php";
$file_handler = fopen($content, 'rw');
$content2 = fread($file_handler, filesize($content));
fclose($file_handler);
// Set print mode to RAW and send PDF to printer
printer_set_option($ph, PRINTER_MODE, "RAW");
printer_write($ph, $content2);
printer_end_doc($ph);
printer_close($ph);
}
else "Couldn't connect...";