btprinter
Mobile icon

BTPrinter CesarBalzer

Stable version 1.0.0 (Compatible with OutSystems 11)
Uploaded
 on 21 November 2022
 by 
5.0
 (2 ratings)
btprinter

BTPrinter CesarBalzer

Details
A cordova plugin for bluetooth printer for android platform. This code is being adapted from a fork of Cordova-Plugin-Bluetooth-Printer, of free use and modifications that will arise for the improvement of the plugin. This plugin is based on: https://github.com/CesarBalzer/Cordova-Plugin-BTPrinter
Read more

Status

Checks current bluetooth active status. Return values:

List

Retrieves the list of paired BT devices and populates the Select Printer dropdown box.

Reset

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.

Line feed

Send LF command (hex A0) to insert a line feed and advance the paper in the printer.

Font demo

Prints a sample of different font types: underline 1-dot, underline 2-dot, bold, font type A, font type B.

Size demo

Prints a sample of different font sizes: 00 normal, 01 reduced, 10 double-height, 20 double-width, 30 double width and height.

Beep x1/x3

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.

Set encoding

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: modelsizeerror correction level. With my generic printer, all models show the same QR code, but size and alignment can be properly set.

BTPrinter plugin QR code sample

BTPrinter plugin QR code sample

Print Barcode

Prints a barcode with these options: system (format), characters positionfontheight. 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)

BTPrinter plugin barcode sample

BTPrinter plugin barcode sample

???????? Test

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: 1114153847 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.

greek language cordova bluetooth printer plugin btprinter

Greek language test with printer plugin using generic cheap printer for latin american market

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

Bluetooth thermal printer cordova btplugin sample ticket

Bluetooth thermal printer cordova btplugin sample ticket

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.
Release notes (1.0.0)
Reviews (1)
by 
2024-04-03
in version 1.0.0
Mantap Pandu...
Team
Other assets in this category