PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



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.

How to interface to receipt printer in a point of sale system?


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
  1. Establish the connection with the receipt printer through PRN.
  2. Writes to the receipt printer through the file handle.
  3. Disconnect the printer.

Related Links

User reviews   Average user ratings:    4.0   (from 13 users)
  1. Ismail Azmath
    January 20, 2008 3:18pm
    Thanks

    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

  2. kksou
    January 20, 2008 9: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

  3. Ismail Azmath
    January 20, 2008 11:03pm

    IC. Thanks man. I'll try it, like i said, when i come to the receipt printing stage. ur help might be needed ;)

  4. Henry Gomez
    April 07, 2008 11:16pm

  5. apmarket
    April 18, 2008 11:16am

  6. kunkun
    April 23, 2008 2:39am

  7. logam sunwares
    July 29, 2008 1:12am

  8. samuel sorri
    July 30, 2008 5:17am

  9. chege
    September 16, 2008 1:57am

  10. Paul Trappitt
    October 18, 2008 10:16am
    an alternative

    Hi,

    I'm currently in the process of creating a system that requires interaction with a receipt printer such as this. I tried various methods but found that writing directly to the printer becomes very tricky if you wish to produce a receipt that looks anywhere near decent. creating the code to produce images or tables etc is very tricky. Also we wanted to allow the clients using the system to create their own receipt templates. The method we opted for was to create a php file containing a html template. PHP code within the template allows content to be added on the fly, then pass the template through dompdf (a php based html->pdf convertor) to produce a pdf file of the exact width and length required. Then pass the pdf file to the windows printer using pdfp.exe. pdfp.exe will print the file through adobe silently in the background. To ensure we have control of the whole process and the print job we're using a class called EasyWMI to interface with the windows wmi printer objects. Using the class we can first check the status of the printer, check all its attributes, then track the print job by name and ensure its been printed. it also facilitates a way to get the exact printer error message into your application to present to the user.

    As I'm sure people will comment, its better to use the printer directly as you have more control. We certainly wasn't keen on passing anything to windows to assume it would do its job properly. With this method however we've been able to emulate the same amount of control over the print job from start to finish, we are able to print very nice looking receipts, and, we can save the pdf file if required.

    Cheers
    Paul

  11. Syazana Amali
    December 08, 2008 10:24pm

  12. steve novick
    February 16, 2009 8:16am

  13. José Franco from Portugal
    April 03, 2009 11:01pm
    Simple question

    How do i convert the data on a html page to the correct dimensions of that printer on the output papel. I have redimension it isnīt ? I haev no idea, Itīs my forst time working with POS printers and i ainīt got any to test the printing . Anyone know any POS printer simulator os something like

    Thans in advance

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved