PHP Print Thermal Receipt Printer

Alihamra picture Alihamra · Dec 31, 2012 · Viewed 8k times · Source

I own Sewoo Thermal Printer that is connected to a local PHP point of sale. Now as a simple print test using php, I wrote the following code :

<?php
$handle = printer_open("THERMAL LK-TXXX");
$handle = printer_open();
?>

And I got this Error :

Fatal error: Call to undefined function printer_open() in C:\wamp\www\frame\reciept.php on line 2

I'm using Wampp as my web server, Windows 7 and I've installed the correct drivers for my printer. How can i fix this problem, Or is there an alternative "Print" methode using PHP to automatically print without showing Print preview?

Thank You

Answer

Eugen Rieck picture Eugen Rieck · Dec 31, 2012

A POS printer is (mostly) not a printer in the sense of using the Windows printing functions to create output, that is quite independent of the device, but simply a sink for serial data in the printer's control language (we built a ticketing system driving very similar printers).

One approach is to user the Win32API extension for PHP and the OpenDriver API, but this turns out to be quite a mess. Best way is to simply fopen() the printer port and write your PCL data via fwrite()