Uploading your logo, print a test receipt on your Clover device. Location You can have customers sign on your Clover device or on a printed paper receipt.
Active12 months ago
We are looking to print to a POS printer connected where apache is running. Due to design of the application, and deployment, printing should be done from Server (it should detect the order and send to different printers and different formats of printing...bill, kitchen orders, and so on...). For this reason and others (like access application from an iPad for example) we discard options like QZ-Print applet and needst o print directly server side.
We searched a lot, and found that there are an extension called php-printer but seems outdated, and just works under WIndows.
We followed this code: (http://mocopat.wordpress.com/2012/01/18/php-direct-printing-printer-dot-matrix-lx-300/)
And it works, but this sends plain text, and we need to send image (logo), and format a more cute bill. We tried creating a PDF and 'sending' to the printer in the same way, but just prints blank.
I found a library to work with network printers (escpos-php on github), but we need to work with USB printers too, to avoid our customers to change hardware.
Some ideas how to achieve this?
Thanks in advance.
GiuGiu
1 Answer
Author of escpos-php here.
If your printers do support ESC/POS (most thermal receipt printers seem to use some sub-set of it), then I think the driver will accommodate your use case: USB or network printing, logo, some formatting. Some of these are quite recent additions.
USB printing
![Receipt book print out Receipt book print out](/uploads/1/2/5/8/125814925/791261543.jpg)
escpos-php prints to a file pointer. On Linux, you can make the USB printer visible as a a file using the
usblp
driver, and then just fopen()
it (USB receipt example, blog post about installing a USB printer on Linux).So printing 'Hello world' on a USB printer is only slightly different to printing to a networked printer:
Or, more like the code you are currently using successfully, you could write to a temp file and copy it:
So in your POS system, you would need a function which returns a file pointer based on your customer configuration and preferred destination. Receipt printers respond quite quickly, but if you have a few iPads making orders, you should wrap operations to each printer with a file lock (flock()) to avoid concurrency-related trouble.
Also note that USB support on Windows is un-tested.
Logo & Formatting
Once you have figured out how you plan to talk to the printer, you can use the full suite of formatting and image commands.
A logo can be printed from a PNG file like so:
And for formatting, the README.md and the example below should get you started. For most receipts, you only really need:
selectPrintMode()
to alter font sizes.setEmphasis()
to toggle bold.setJustification()
to left-align or center some text or images.cut()
after each receipt.
I would also suggest that where you are currently using an example that draws boxes like this:
You could make use of the characters in IBM Code page 437 which are designed for drawing boxes that are supported by many printers- just include characters 0xB3 to 0xDA in the output. They aren't perfect, but it looks a lot less 'text'-y.
Full example
The below example is also now included with the driver. I think it looks like a fairly typical store receipt, formatting-wise, and could be easily adapted to your kitchen scenario.
Scanned output:
PHP source code to generate it:
mike42mike42
Not the answer you're looking for? Browse other questions tagged phpprintingkiosk or ask your own question.
![Paper Paper](http://www.printablereceipttemplate.com/wp-content/uploads/2017/11/receipt-template-pages-v5-standard-invoice-template-and-shortcut-key-printed-qaeBLm.jpg)
Over the last year, [James] has been a part of a few commercial projects that used a thermal receipt printer as part of the build. Something must have cracked in his mind, because [James] spent a lot of time developing a way to print customized content on receipt printers, connecting these printers to the Internet, and sharing content with other Internet-connected receipt printers. Even [James] doesn’t know why he spent so much time on this project; [James] figured he was bound to find something interesting. We’ve got to commend him for that.
[James] had been aware of the Adafruit Thermal Printer Library, but this library is a little kludgy. Text is the Adafruit Library’s forte, and while graphics and non-ASCII characters are possible they’re certainly not easy to print with the existing libraries. With his current system based on HTML, CSS, and Javascript, [James] has a really easy way to print anything he can put on a webpage on receipt paper.
Getting his receipt printer onto the Internet had its own challenges. After wrangling with the Arduino Ethernet library through the month of February, [James] realized larger prints (about 15cm of paper) would fail inexplicably. To get around this, [James] wrote an HTTP client for the Arduino that would fetch data, put it on the SD card, and then start printing.
Right now, [James]’ project is a polished as anyone could hope. We’re a bit concerned – although we completely understand – that he could get sucked into the black hole of pointless development of receipt printer software so easily. All was not for naught, though; now anyone can make very professional-looking prints on receipt paper very easily.