The ESC/POS Simple Converter enables to send formatted text, images, bar codes and QR codes from App Inventor to a bluetooth thermal printer without the need of having knowledge in ESC/POS programming.
This extension simplifies the communication with Bluetooth thermal printers and makes possible to create awesome apps. The converter provides blocks for basic ESC/POS commands (Epson Standard Code for Point Of Sale). To send your data to the printer, just combine one block from the extension with a SendBytes block from the BluetoothClient component. The ESC/POS Simple Converter returns the byte sequence your ESC/POS printer expects.
For example, you can print images from the assets, the SD card or the web. Just provide the name or the URL of the image. You can also take a photo with your camera and directly send it to your
printer. A dithering algorithm is applied to create the illusion of a grayscale instead of monochrome black.
In the following you can find a list of all the blocks and some examples how to use them. The blocks for printing images, text and QR codes can be utilized with various options but also with reasonable default values. Take into account that some manufacturers might use different commands. If you have a manual, we can find a solution.
After I have read several questions concerning bluetooth printers in the app inventor forum, I decided to develop this extension in order to simplify things for inventors who want to print tickets, invoices or receipts. I would like to offer the ESC/POS Simple Converter as a paid extension for 16 EUR (20 USD). If you want to purchase it, you can contact me via the contact form.
You can download my demo app to test the functioning of the extension with your devices.
Note that different manufacturers use slightly different command sets. Thus I have implemented multiple commands for QR code and image printing. You have to try which one is supported by your printer model.
Text can easily be converted with the ConvertText block which provides optional encoding. Before sending text, you can choose font sizes and select various formatting modes including bold, underlined and inverted. Most printers support 2 fonts: the standard font A and a smaller font B. Set otherFont to true to choose the smaller font.
For image printing, two different ESC/POS commands have been implemented. You can use the default blocks, but also set parameters like the horizontal pixel size and the threshold for converting to black and white. In order to imitate grayscale images, use the dithering option. If you want to take advantage of the paper format, rotate your pictures if they have been taken in landscape mode.
The extension enables to create barcodes and QR codes. The QR code block chooses a suitable size according to your data. If you want to print barcodes, you have to provide appropriate data and the index that indicates the barcode system to be used.
Alignment works for text as well as for barcodes, QR codes and images.
At first, you always have to initialize the printer. Optionally you can select a character code page (see your manual). Use the LineFeed to create a line break. If supported, you can cut the paper.
After you have enabled bluetooth and paired the two devices, you can set up a connection using the BluetoothClient component. Select your printer from the list of AddressesAndNames and call the Connect method.
You can use the Camera component to take an image and directly send it to your bluetooth printer. Other image sources can be the SD card and the web.
For printing images, just provide the path, an URL or the name of the image. In the example, the image has to be in the assets. The text formatting mode and alignment is active until you reset it.
The ConvertToQRCode block only needs a text. Optionally, you can change the error correction level and vary the printing size of the QR code.
To print arabic (or other scripts), just choose an appropriate encoding and codepage according to your printer manual. My printer, for example, supports four arabic code pages, which I managed to use together with the following encodings:
|code page number||code page name||Java encoding|
The code page number is used as input of the SelectCharacterCodePage block, whereas the encoding is used in the ConvertTextWithOptions block. To find the correct Java encodings for other languages, these lists may be helpful:
My recommendation is to use ISO-8859-6 for arabic scripts, which was the only one that supported right-to-left printing on my printer. When using the other code pages, I had to reverse the text in advance
Hooray! Some new features have been added to the extension: