Sample Code 397: How to interface to receipt printer in a point of sale system? |
|
Written by kksou
|
|
Sunday, 23 December 2007 |
|
Problem This is in response to duez1981's post titled 'php-gtk2 point of sale system'.
He is writing a point-of-sale (POS) system using PHP-GTK2, and he wants to know how to link to a receipt printer as shown below.

Solution
- A standard receipt printer such as the Epson TM-T88III receipt printer uses the parallel port.
- To print to the parallel-port receipt printer, you print through port PRN (exactly the same as printing from DOS prompt).
- From within PHP-GTK2, you need to first establish the connection with the printer by using
$handle = fopen("PRN", "w");
- Thereafter, to print anything to the printer, you just "write" to it like the file handle:
fwrite($handle, 'text to printer');
- There are newer receipt printer that uses USB. I believe you should be able to print to such printers through PRN too.
Sample Code 1 2 3
| <?php $handle = fopen("PRN", "w"); // note 1
fwrite($handle, 'text to printer'); // note 2
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Establish the connection with the receipt printer through PRN.
- Writes to the receipt printer through the file handle.
- Disconnect the printer.
Related Links
User reviews Average user ratings: 3.5 (from 8 users) Note: You have to be a registered member to leave a comment. Free registration here. |
January 20, 2008 4:18pm
Hey, Thanks for the info you have given here. I'm currently working on a similar project as duez1981, and was doing some preparational research. I will try this as soon as i get to the receipt printing stage.
But i have a question: how do i set up columns for, say, Item code, Description, price?
Please do enlighten me here...
thanks,
Micro
January 20, 2008 10:26pm
Hi Micro, Not sure if you have played with those stone-age dot-matrix printers before? You're be surprised that a standard thermal receipt printer such as the Epson TM-T88III receipt printer mentioned above works exactly like a dot-matrix printer! Each printer usually come bundled with some fixed-width fonts. And a standard receipt printer is usually 40 characters in width. (There are some with 32 characters width.) So to print columns such as item code and description, it's direct, "manual" positioning of strings with padded spaces, since they are all fixed width characters.
Regards,
/kksou
January 21, 2008 12:03am
IC. Thanks man. I'll try it, like i said, when i come to the receipt printing stage. ur help might be needed ;)
April 08, 2008 12:16am
April 18, 2008 12:16pm
April 23, 2008 3:39am
July 29, 2008 2:12am
July 30, 2008 6:17am