B4A Library SD: BT Printer (Bluetooth)

(No WRAP, No Java Only B4A)

library allows you to print text and image to a bluetooth thermal printers with ESC/POS language
(Here for B4J, Here for B4i)

To print the QR CODES with your BT thermal printer you can create an image containing the QR code with the help of the @Erel library (here) or can use library of @Johan Schoeman (here)

Required: B4A 8.8+ and Serial Library 1.30+
Make sure the library meets all your needs, is compatible with the printer you need to use.

To try print with the demo version you can only use the FlushAndClose command which lasts 14 days and then disables.
The full version of the library will be issued to those making a donation (Contact me in private before making a donation). In the donation indicate the library you want and your NickName. Those requesting the full version will receive updates for 3 months.



Version: 0.21
  • BT_Printer
    Note: AddPermission(android.permission.ACCESS_COARSE_LOCATION)
    • Events:
      • BluetoothIsDisabled
      • ConnectedToPrint (Success As Boolean)
      • DataReceived (Buffer() As Byte)
      • DisconnectToPrint (Mac As String)
      • DiscoveryComplete (Printers As Map)
      • DiscoveryFinished
      • DiscoveryNewPrinter (PrintedFound As Map, DeviceClass As Int)
      • DiscoveryNoDeviceFound
      • ErrorDiscovery
      • ListPrinterAssociated (ListNameAndMac As Map)
      • SendingError (Mac As String)
      • SendTerminated
    • Fields:
      • Const_AUDIO_VIDEO As Int
      • Const_COMPUTER As Int
      • Const_HEALTH As Int
      • Const_IMAGING As Int
      • Const_MISC As Int
      • Const_NETWORKING As Int
      • Const_PERIPHERAL As Int
      • Const_PHONE As Int
      • Const_TOY As Int
      • Const_UNCATEGORIZED As Int
      • Const_WEARABLE As Int
    • Functions:
      • AddBuffer_ArrayByte (B As Byte()) As String
      • AddBuffer_BarCode (Code As String) As String
      • AddBuffer_Bitmap (Bmp As Bitmap, ShiftLeft As Int) As String
      • AddBuffer_BitmapAlternativeCoding (Bmp As Bitmap) As String
      • AddBuffer_List_Write (list As List) As String
      • AddBuffer_List_WriteLine (list As List) As String
      • AddBuffer_Tab (ArrayTab As Int()) As String
      • AddBuffer_Write (Text As String) As String
      • AddBuffer_WriteLine (Text As String) As String
      • AddPrintDefineImage As String
      • CenterJustify As String
        after this command calls SendBufferToPrinter
      • ChangeEncoding (EncodingType As String) As String
      • Class_Globals As String
      • ClearBuffer As String
      • Close As String
      • Connected As Boolean
      • DefineImage (Image As Bitmap)
      • flushAllAndClose
      • Initialize (CallBack As Object, EventName As String, EncodingType As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • InitializePrinter As String
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • LeftJustify As String
        after this command calls SendBufferToPrinter
      • Preview As Bitmap
      • ResetPreViewWidth (NewWidth As Int) As String
      • RightJustify As String
        after this command calls SendBufferToPrinter
      • SearchNewPrinter As String
        select --------------------------------------------
      • SelectFromAssociatedPrinter As String
      • SelectFromMac (Mac As String) As String
      • SendBufferToPrinter
      • SetCodePage (Code As Byte) As String
        es. Printer.SetCodePage(06) for umlauts char
    • Properties:
      • CodeTable
        es. printer.setCodeTable(Ecoding.Code_WPC1252)
        aftet this command calls SendBufferToPrinter
      • Spacing
        after setSpacing command calls SendBufferToPrinter
    Code module
    Subs in this code module will be accessible from all modules.
    • Fields:
      • BoldOff As String
      • BoldOn As String
      • DoubleOff As String
      • DoubleOn As String
      • FontA_Bold As String
      • FontA_DoubleHight As String
      • FontA_DoubleWide As String
      • FontA_DoubleWideHeight As String
      • FontA_Normal As String
      • FontB_Bold As String
      • FontB_DoubleHeight As String
      • FontB_DoubleWide As String
      • FontB_DoubleWideHeight As String
      • FontB_Normal As String
      • Horizzontal As String
      • InitializePrinter As String
      • ItalicFontOff As String
      • ItalicFontOn As String
      • NoUnderline As String
      • QueryErrorCauses As String
      • QueryOfflineCauses As String
      • QueryPaperStatus As String
      • QueryPrinterStatus As String
      • Underline1 As String
      • Underline2 As String
      • Vertical As String
    • Functions:
      • Process_Globals As String
  • Encoding
    Code module
    Subs in this code module will be accessible from all modules.
    • Fields:
      • Chinese As String
      • ChineseS As String
      • Code_PC437 As Int
      • Code_PC850 As Int
      • Code_PC857 As Int
      • Code_PC858 As Int
      • Code_PC860 As Int
      • Code_PC863 As Int
      • Code_WPC1252 As Int
      • DOS_Latin_1 As String
      • IBM_PC As String
      • ISO8859 As String
      • UTF8 As String
      • Windows1252 As String
    • Functions:
      • Process_Globals As String


  • Sample1.zip
    10.2 KB · Views: 1,331
  • SD_BT_Printer 0.18 DEMO.zip
    21.5 KB · Views: 709
Last edited:


Licensed User
Examples and documentation

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Stampa As BT_Printer
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private Label1 As Label
    Private ListView1 As ListView
    Private RadioButton1 As RadioButton
    Private RadioButton2 As RadioButton
    Private RadioButton3 As RadioButton
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
End Sub

Sub Button2_Click
End Sub

Sub Stampa_ListPrinterAssociated (ListNameAndMac As List)
    For Each BT As NameAndMac In ListNameAndMac
End Sub

Sub Stampa_DiscoveryNewPrinter (Print As NameAndMac, DeviceClass As Int)
     Log("DevCl: " & DeviceClass)
End Sub

Sub Stampa_DiscoveryFinished
    Log("Fine ricerca")
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
End Sub

Sub Stampa_ConnectedToPrint
End Sub

Sub Stampa_Send_Terminated
End Sub

Sub Printer
        Stampa.AddBuffer_Writeline(ESC_POS.BoldOn & "Hallo dear" & ESC_POS.DoubleOff)
        Stampa.AddBuffer_Writeline("How are you?")
        Stampa.AddBuffer_Writeline("Fine thank's")

        ' if AddBuffer_Bitmap don't work

        ' If you wont add a BarCode Image
    End If

    Label1.Text = Stampa.Preview
End Sub

The library is equipped with a series of ESC commands, you can use them by listening to ESC_POS.

For example, if you would like to reset the printer:

Those who have a Chinese printer sometimes have difficulty printing the Euro (€) character. By setting the Code Page PC858 and Chinese (or simplified Chinese) Encoding you will be able to print it
Printer.AddBuffer_WriteLine("10 €.")

How to get text alignment:
Printer.AddBuffer_Writeline(Chr(27) & Chr(97) & Chr(50))

Printer.AddBuffer_Writeline(Chr(27) & Chr(97) & Chr(49))

Printer.AddBuffer_Writeline(Chr(27) & Chr(97) & Chr(48))
Last edited:


Licensed User
For the moment I added a few commands. In the future I will put other commands if I can, and if I can also print BITMAP.

For now, you have to be satisfied with this :p


B4X founder
Staff member
Licensed User
Longtime User


Licensed User
In fact, I found this problem and I did not understand the reason. I followed other examples using TextWriter and TextReader.

Thanks for the tip. I update the source code.
Last edited:


Licensed User
Longtime User
When I try to run the example I get the following error
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoSuchMethodError: No static method ToastMessageShow(Ljava/lang/String;Z)V in class Lanywheresoftware/b4a/keywords/Common; or its super classes (declaration of 'anywheresoftware.b4a.keywords.Common' appears in /data/app/b4a.example-1/base.apk)
    at b4a.example.bt_printer._initialize(bt_printer.java:424)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6186)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
** Activity (main) Resume **


Licensed User
The library is for b4A version 6.50 (or at most 6.80) because I use this version

Someone did me kindness to compile a version for B4A 7+
This version modifies a method: Send_Buffer_to_Print becomes Send_Buffer_to_Print_flush

you can also find an Library for 7+ and example in the attachment

Update for B4A 8 see post#1
Last edited:


Licensed User
You still have to thoroughly test the 2 methods for bitmap printing. They may not work properly.
Eventually let me know if it works for you


Active Member
Licensed User
Longtime User
Hi. first of all, sorry for my english.
We were testing the example in B4A 7.3 and it prints rare characters instead of the image.


Licensed User
Longtime User
Hi. first of all, sorry for my english.
We were testing the example in B4A 7.3 and it prints rare characters instead of the image.
this also happened to me, check the type of language your printer uses, and change it to esc/pos, my printer was a zebra and has by default the zpl lenguage


Licensed User
At this time, the method for printing images was not finished. It is not included in the description. We will have to wait for an update.
For the moment the method does not work on all printers.


Active Member
Licensed User


Licensed User
Probably at the next update will be included the printing of images, and the QR and USB connection. For the moment the project is stopped because I'm working on other libraries and apps with higher priority

But if you have good will on this forum find the necessary to develop your own library,
There are some B4A developers who have already add print/pos with USB to App


Licensed User
Update to version 0.05 at post#1 The AddBuffer_Bitmap function has been tested and is working on most printers. Alternatively you can use AddBuffer_Bitmap2