B4A Class Bluetooth ESC/POS Printer Class

For the last couple of weeks I have been playing with an 80mm Bluetooth ESC/POS thermal printer I bought off eBay, new and delivered, for the ludicrously cheap price of £20. While the print quality, particularly of images with large areas of black (they are gray due to power supply or thermal dissipation limitations probably), is not great it is adequate. The printer itself seems to be a generic Chinese unit (no surprise there then!) which is re-badged by all and sundry and sold at a remarkably wide range of prices.

Here then is a Printer class that will connect by Bluetooth to the printer and enable access to most of the printer functions, including barcodes and image preparation and printing. The included demo shows the capabilities that are available. To run the demo you will need a paired Bluetooth printer that is switched on. The Printer class uses the BitmapCreator, RandomAccessFile and Serial libraries.

On my printer the only thing that doesn't seem to work properly is QR code generation. Small QR codes don't seem to be able to be decoded by scanners and larger ones look obviously wrong with part of the top of the code replicated at the bottom when printed.

The obvious capabilities missing (so far!) are user defined characters and non-volatile bit images. Also not implemented are some codes that are either duplicates of available commands or ones whose functions I don’t understand.

The class module is included as source code in the demo so you can add any missing capabilities you need. If you add a significant one then please post it for others to play with.

EDIT: Version 2 now posted includes support for creating custom characters. See post #5 for details
 

Attachments

  • BluetoothPrinter_v2.0.zip
    298.6 KB · Views: 3,382
Last edited:

agraham

Expert
Licensed User
Longtime User
While preparing the above Printer class I have spent hours downloading, trying and discarding printer apps from the store. There are two that I have kept, both ad-free as I discard most anything with ads immediately.

Pointillist by Aption
This is a simple app that can print any image on the device. It has some simple image editing capabilities and has much more sophisticated dithering algorithms than I have used so the image quality is slightly better, but still limited by the crudity of the printer.

RawBT by 402d
As well as being able to print text, PDF and image files this app can function as an Android print service so that content can be printed from any app that implements the Android printing functions. To print images on my printer it needs to use the "ESC * 33" Setting. There is a fee to remove the banner text notification on printouts including an annual option which I have paid.

It you have found something better then please post details.
 

agraham

Expert
Licensed User
Longtime User
Last edited:

agraham

Expert
Licensed User
Longtime User
Version 2 now posted includes support for creating custom characters. Although the documentation for my printer says that it should be able to create custom characters both for font A and font B it only works for font A on my printer. Selecting UseCustomCharacters=True when CharacterFont=1 causes the printer to turn itself off :(

However the custom character generation and use works fine for font A and as creating them can be a chore I have included some methods for drawing graphics primitives on a custom character so you can more easily create your mini-masterpieces of art. :)
 
Last edited:

djmainero

Member
Licensed User
Longtime User
Hi there!
First of all, thanks for sharing the code!
I have a question, I was trying to center the printed image with the function "PrintImage ()" without success. I tried "setJustify (1)" but just center the text.

From already thank you very much!
 

djmainero

Member
Licensed User
Longtime User
Thanks for the reply!
I'm going to fill in white the img to "center it".
Again thanks!
 

vvg

Member
Licensed User
Longtime User
For the last couple of weeks I have been playing with an 80mm Bluetooth ESC/POS thermal printer I bought off eBay, new and delivered, for the ludicrously cheap price of £20. While the print quality, particularly of images with large areas of black (they are gray due to power supply or thermal dissipation limitations probably), is not great it is adequate. The printer itself seems to be a generic Chinese unit (no surprise there then!) which is re-badged by all and sundry and sold at a remarkably wide range of prices.

Here then is a Printer class that will connect by Bluetooth to the printer and enable access to most of the printer functions, including barcodes and image preparation and printing. The included demo shows the capabilities that are available. To run the demo you will need a paired Bluetooth printer that is switched on. The Printer class uses the BitmapCreator, RandomAccessFile and Serial libraries.

On my printer the only thing that doesn't seem to work properly is QR code generation. Small QR codes don't seem to be able to be decoded by scanners and larger ones look obviously wrong with part of the top of the code replicated at the bottom when printed.

The obvious capabilities missing (so far!) are user defined characters and non-volatile bit images. Also not implemented are some codes that are either duplicates of available commands or ones whose functions I don’t understand.

The class module is included as source code in the demo so you can add any missing capabilities you need. If you add a significant one then please post it for others to play with.

EDIT: Version 2 now posted includes support for creating custom characters. See post #5 for details
 

vvg

Member
Licensed User
Longtime User
Many thanks agraham, that you have made available this class. I really appreciate because the printer library so far i was using was lacking something (looking tedious job for expected output and tedious indeed also for a hardcore non-java vb6 programmer like me) and even after paid libraries i used also didn't made my work that easy what this class has made....
Thanx!! Thanx again...
 

bl4ck4nt

Member
Licensed User
Longtime User
Thanx for your library agraham, i try this library if i disconnect always show "Error: java.io.IOException: bt socket closed, read return: -1", i used MINI Thermal Printer (POS-5802DD)
 

lewi

New Member
Licensed User
Longtime User
In my printer the qrcode does not print at all, it only prints text "Thanks for using our thermal printer!"
 

lewi

New Member
Licensed User
Longtime User
I think it can print qrcode but cannot decode by scanner. In my case it does not print qrcode at all.
 

vvg

Member
Licensed User
Longtime User
Best solution. I got here what I wanted.
But agraham, if you can will you please
provide USB printing code in the class?
 

vvg

Member
Licensed User
Longtime User
For the last couple of weeks I have been playing with an 80mm Bluetooth ESC/POS thermal printer I bought off eBay, new and delivered, for the ludicrously cheap price of £20. While the print quality, particularly of images with large areas of black (they are gray due to power supply or thermal dissipation limitations probably), is not great it is adequate. The printer itself seems to be a generic Chinese unit (no surprise there then!) which is re-badged by all and sundry and sold at a remarkably wide range of prices.

Here then is a Printer class that will connect by Bluetooth to the printer and enable access to most of the printer functions, including barcodes and image preparation and printing. The included demo shows the capabilities that are available. To run the demo you will need a paired Bluetooth printer that is switched on. The Printer class uses the BitmapCreator, RandomAccessFile and Serial libraries.

On my printer the only thing that doesn't seem to work properly is QR code generation. Small QR codes don't seem to be able to be decoded by scanners and larger ones look obviously wrong with part of the top of the code replicated at the bottom when printed.

The obvious capabilities missing (so far!) are user defined characters and non-volatile bit images. Also not implemented are some codes that are either duplicates of available commands or ones whose functions I don’t understand.

The class module is included as source code in the demo so you can add any missing capabilities you need. If you add a significant one then please post it for others to play with.

EDIT: Version 2 now posted includes support for creating custom characters. See post #5 for details
 
Top