PHP Send data to Printer

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

Upvotes: 0

Views: 6866

Answers (2)

Raja Guru
Raja Guru

Reputation: 1

$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...";

Upvotes: 0

BenM
BenM

Reputation: 53198

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.

Upvotes: 1

Related Questions