Demo app for testing the functions from the cordova-plugin-btprinter, which allows to print text, images, barcodes and QR codes to any bluetooth printer from your Cordova app. Source code available in GitHub.
To test the demo app:
- Pair your android device with the bluetooth printer and turn bluetooth on
- Start the demo app and click status to check if bluetooth is active
- Click list to view all paired bluetooth devices
- Click connect and wait a few seconds
- Click connected to check if the connection is active
- Start testing the provided methods as desired.
Checks current bluetooth active status. Return values:
Retrieves the list of paired BT devices and populates the Select Printer dropdown box.
Send ESC @ (hex 1B40) to initialize the bluetooth printer. This command has the same effect as restarting the printer, so your encoding set with setEncoding will be cleared as well.
Send LF command (hex A0) to insert a line feed and advance the paper in the printer.
Prints a sample of different font types: underline 1-dot, underline 2-dot, bold, font type A, font type B.
Prints a sample of different font sizes: 00 normal, 01 reduced, 10 double-height, 20 double-width, 30 double width and height.
Sends a 1B420109 or 1B420309 POS command to beep the printer’s buzzer 1 or 3 times respectively. These codes do not match the EPSON buzzer codes, but they worked on the generic printer I’ve tested. This method is useful to beep the device after the printing process is complete.
Sets the encoding method used by the printer plugin, applied with mmOutputStream.write(msg.getBytes(encoding)); whenever a string is sent to the printer.
Set inverted mode
Sends POS command 1D4201 to enable inverted mode text and 1D4200 to disable it.
Send POS command
Sends an arbitrary ESC/POS command to the bluetooth printer. Refer to your particular printer model for supported commands, most printers should support the official EPSON commands by default.
Remember to send decimal values in hexadecimal, for example, to set the Denmark II character set (10) send it as 0A. The full POS command to set this charset would be 1B520A. You may also send a test print command to check the printer’s supported characters.
Print base 64 image
Tests the printBase64 method to print the provided base-64 encoded image. There is another method to print images by path, but it’s not implemented in this demo app to avoid dealing with the endless caveats of file system plugin.
Print QR Code
Prints a Quick Response code with these options: model, size, error correction level. With my generic printer, all models show the same QR code, but size and alignment can be properly set.
Prints a barcode with these options: system (format), characters position, font, height. With my cheap portable bluetooth printer, all fonts are the same, and only 2 height settings are applicable. Formats supported:
- UPC-A (numbers 0-9)
- UPC-E (numbers 0-9)
- EAN13 / JAN13 (numbers 0-9)
- EAN8 / JAN8 (numbers 0-9)
- CODE39 (supports numbers+text)
- ITF (does not work in my brandless printer)
- CODABAR (supports numbers+text)
Greek language test, works as follows:
- Calls the BTPrinter.setEncoding function with ISO-8859-7 character set.
- Sends an ESC + t command (1B74 in hex) followed by the character tables: 11, 14, 15, 38, 47 in hex format, to set the character code table, and prints a sample text with each table. These tables correspond to all Greek code page variations CP851, CP737, ISO-8859-7, CP869 and CP1253 for EPSON printers.
- By calling the demo app function testCP(cp_table_number) you can test any character table easily, however, remember to set the encoding properly before printing.
This function is quite tricky, and it failed to print properly in my generic printer, even after setting the encoding correctly. However, the printer’s demo ticket does not show non-latin-1 characters properly either, my guess is that the printer has left out these languages to save a few KB of memory (or neither me nor the manufacturer knows the table numbers for other languages). This should work just fine with decent printers, or those aimed for specific non-western-european markets.
Please send your comments and feedback in this page regarding printing in other languages and charsets with your specific printer model.
Sample ticket created by demo app
The previous ticket shows the thermal printer’s output for different text formats and sizes, a base 64 encoded image sample, and a reversed color text sample.
Cordova BTPrinter plugin usage considerations
- The plugin does not discover nor pair with devices, therefore the user must pair with the printer using the Android Bluetooth/Connection settings before using the print functions.
- The plugin will list all paired Bluetooth devices, not just printers. If a single device is found, we could assume it is a bluetooth printer and go ahead with the connection, but if more than 1 device is found a Select Bluetooth Device dialog should be implemented.
- Do not reconnect to an already connected printer, this will return an error. Use the connected method to check if a printer is already connected and jump directly to printing if this is the case.
Printer used for this demo
The demo app has been tested with a generic bluetooth portable thermal printer with a meaningless model number, as shown here. Device fails to print non-latin-1 characters even in the demo ticket printed by itself, probably because it was specifically aimed to the latin american market.
Download demo app
- Download release APK v1.2.1 (minSdkVersion 22)
- Download www source code
Use the comments section here for demo app-related issues, and the GitHub issues tracker for plugin-related ones.