B4A Library SD: BT Printer (Bluetooth)

(No WRAP, No Java Only B4A)

BT_Printer
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.


Video1.gif
upload_2018-9-2_17-24-41.png



SD_BT_Printer

Author:
Star-Dust
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
  • ESC_POS
    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
 

Attachments

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

Star-Dust

Expert
Licensed User
To speed up processing I just placed the command: Printer.SelectFromMac("00:08:1B:95:42:BD") in B4A and the flow goes to Printer_ConnectedToPrint (Success As Boolean) as true.

1. In B4J (Printer.SelectFromMac("00081B9542BD")) it doesn't work, I have to search first. Is it possible to connect directly without have to search the device?
Thank you for the question. It is possible to do it.
However, questions concerning B4J should be asked on the forum relating to the library in the B4J version.
This thread is dedicated to the B4A version. See the link below.

2. Is it possible to keep printing from both devices -Mobile and PC? . Do I have to logout the printer with "close" and search the printer again when I change the sender?

Tks a lot for the reply
The Bluetooth SPP opens a connection and maintains it unlike BLE which sends a Message but does not maintain the connection.
So it is not possible, the printer does not accept two connections.
If the printer is connected to a device it will not accept another connection.
It is necessary to close the channel with the first to make the printer available to another connection
 
Last edited:

lelelor

Member
Licensed User
(No WRAP, No Java Only B4A)

BT_Printer
library allows you to print text and image to a bluetooth thermal printers
(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+

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.


View attachment 71755 View attachment 71781



SD_BT_Printer

Author:
Star-Dust
Version: 0.19
  • BT_Printer
    AddPermission(android.permission.ACCESS_COARSE_LOCATION)
    • Events:
      • BluetoothIsDisabled
      • ConnectedToPrint (Success As Boolean)
      • DataReceived (Buffer() As Byte)
      • DisconnectToPrint (Mac As String)
      • 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) per dieresi char
    • Proprietà:
      • CodeTable
        es. printer.setCodeTable (Ecoding.Code_WPC1252)
        dopo che questo comando chiama SendBufferToPrinter
      • Spaziatura
        dopo che il comando setSpacing chiama SendBufferToPrinter
  • Modulo codice ESC_POS I sottotitoli in questo modulo codice saranno accessibili da tutti i moduli.
    • Campi:
      • Grassetto come stringa
      • 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
      • Orizzontale come stringa
      • InitializePrinter As String
      • NoUnderline As String
      • QueryErrorCauses As String
      • QueryOfflineCauses As String
      • QueryPaperStatus As String
      • QueryPrinterStatus As String
      • Sottolineato1 come stringa
      • Sottolineato2 come stringa
      • Verticale come stringa
  • Modulo di codifica del
    codice I
    sottotitoli in questo modulo di codice saranno accessibili da tutti i moduli.
    • Campi:
      • Cinese come stringa
      • 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 come stringa
      • UTF8 As String
      • Windows1252 come stringa
[/CITAZIONE]
Premetto che sono nuovo di B4A, ho scaricato gli esempi da stampare sulla stampante BT ma mi chiede la libreria byteconver.jar, mi potete aiutare? Grazie
 

Star-Dust

Expert
Licensed User
You can find the ByteConverter library here

 

Kevin Hartin

Active Member
Licensed User
This is an interesting option for me in printing to a BT printer for a new Invoicing app I am making, however....

  1. There seems to be some inconsistency in connecting to a BT device. about 60% of the time when I see the trying to connect message in the log, nothing happens and the other 40% I get the Connected popup and all is good. I feel this may be because something else is going on the the background.
  2. When I scan for Printers I get my printer listed twice.
  3. Once connected, I can print text fine, but when I send the QRcode from the assets dir, it prints about half of it then stops.
    20210404_114635 (2).jpg

  4. When I try the mixed it prints even less of the QRcode and then launches into about 30cm of junk.
    20210404_114712.jpg
  5. It seems to disconnect the printer after every print job as I have to reconnect before testing again. I cannot see a close in the code, so suspect that it is part of the library. Is it possible or feasible to connect and keep a session open indefinately? Is there a means to check the connections status and automatically connect if needed?
  6. Is it feasible to select a printer and store it's details in a txt file or sqlite DB for automatic connection at a later time? The environment where this will be used will not change unless another printer is installed.
NOTE: I am testing with a very cheap chinese receipt printer that I have previously used sucessfully for receipt and image printing. This printer does not have the ESC/POS codes to generate a QRcode, but as stated, it has previously printed QRcodes generated by a Web app and sent to it by USB.

Thanks,
Kev
 

Star-Dust

Expert
Licensed User
Most of the problems you have listed depend on the quality of the printer. None of these depend on the library

1) There is no background element. Makes a simple Bluetooth SPP connection. Some inexpensive printers are not immediately ready when they receive a connection request.

2) When the search is started, only the underlying serial library is performed. Whenever a new printer is discovered it raises the event. If the event is raised multiple times it is a printer or Android device problem.

3) It's a printer problem. The carriage does not drag the paper and everything is printed on the last line. Try to pull the paper lightly as it comes out and it should print everything. It also may not keep the buffer

4) As specified along the thread if there are images you have to print them immediately, this is because the android device may have a small cache and alter the commands. Then in mixed contents send to printer right after inserting the image

5) The bluetooth printer often loses the connection, especially if it is cheap. My library automatically reconnects when you relaunch the print. You don't need to. Not all printer models send the disconnect signal, so it becomes obvious at the time of printing that it generates an error.
My library autonomously in the presence of this error reconnects.

6) Yes, it is possible, you must enter the MAC code already stored in the selected printer. (see here)

7) To generate QR codes there is an Erel library that produces an image with the QR code. This image (which respects the dimensions) can be sent for printing (see here)

In conclusion, the cheap printer saves you money but gives you a lot of headaches.
 

lelelor

Member
Licensed User
Sample:

B4X:
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:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("MAIN")
    ListView1.SingleLineLayout.Label.TextSize=14
    ListView1.SingleLineLayout.ItemHeight=30dip

    Stampa.Initialize(Me,"Stampa",Encoding.Windows1252)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    ListView1.Clear
    Stampa.SelectFromAssociatedPrinter
End Sub

Sub Button2_Click
    ListView1.Clear
    Stampa.SearchNewPrinter
End Sub

Sub Stampa_ListPrinterAssociated (ListNameAndMac As List)
    ListView1.Clear
    For Each BT As NameAndMac In ListNameAndMac
        ListView1.AddSingleLine2(BT.Name,BT.Mac)
    Next
End Sub

Sub Stampa_DiscoveryNewPrinter (Print As NameAndMac, DeviceClass As Int)
     Log("DevCl: " & DeviceClass)
     ListView1.AddSingleLine2(Print.Name,Print.Mac)
End Sub

Sub Stampa_DiscoveryFinished
    Log("Fine ricerca")
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
    Stampa.SelectFromMac(Value)
End Sub

Sub Stampa_ConnectedToPrint
    Printer
End Sub

Sub Stampa_Send_Terminated
    Log("Finish!!")
    Stampa.Close
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")
        Stampa.AddBuffer_Bitmap(File.DirAssets,"qr.jpg",0)

        ' if AddBuffer_Bitmap don't work
        'Stampa.AddBuffer_Bitmap2(File.DirAssets,"qr.jpg")

        ' If you wont add a BarCode Image
        'Stampa.AddBuffer_BarCode("123456/A")
    End If

    Stampa.SendBufferToPrint
    'Stampa.flushAllAndClose
    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:
B4X:
Printer.AddBuffer_ArrayByte(ESC_POS.InitializePrinter.GetBytes("UTF8"))
'or
Printer.AddBuffer_Write(ESC_POS.InitializePrinter)


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
B4X:
Printer.CodeTable=Encoding.Code_PC858
Printer.ChangeEncoding(Encoding.Chinese)
Printer.AddBuffer_WriteLine("10 €.")
hello, it does not work, on the contrary the printer stops responding to the "€" character but if I do print it from the printer it prints correctly.



sorry but it has become a matter of principle hihihi
 

Star-Dust

Expert
Licensed User
hello, it does not work, on the contrary the printer stops responding to the "€" character but if I do print it from the printer it prints correctly.



sorry but it has become a matter of principle hihihi
this works on my printer.
You need to try other encodings to find the correct one for your printer. I don't know how to give you any further help
 

james_sgp

Active Member
Licensed User
Hi, I`m trying to figure out how to print in larger text; has anyone been able to do that?

James
 

Kevin Hartin

Active Member
Licensed User
Double High on Char a is ESC!w or send Chr(27) & "!" & Chr(16)
Double High on Char b is ESC!x or send Chr(27) & "!" & Chr(17)

I use the following for text receipt printing
escpos:
    Dim aNormal As String = Chr(27) & "!" & Chr(0)
    Dim aBold As String = Chr(27) & "!" & Chr(8)
    Dim aDoubleWide As String = Chr(27) & "!" & Chr(32)
    Dim aDoubleHigh As String = Chr(27) & "!" & Chr(16)
    Dim aDoubleWideHigh As String = Chr(27) & "!" & Chr(48)
    Dim bNormal As String = Chr(27) & "!" & Chr(1)
    Dim bBold As String = Chr(27) & "!" & Chr(9)
    Dim bDoubleWide As String = Chr(27) & "!" & Chr(33)
    Dim bDoubleHigh As String = Chr(27) & "!" & Chr(17)
    Dim bDoubleWideHigh As String = Chr(27) & "!" & Chr(49)
    Dim cut As String = Chr(27) & Chr(105)
I also set the num of printing cols for each char in globals
<code>
Dim bCols As Int = 42 'for 78mm 32 for 58mm
Dim bCols As Int = 56 'for 78mm 42 for 58mm
[/CODE]
and also have a few subs that help me format stuff across the page;
subs:
Sub headingLine(fill As String,text As String,width As Int) As String
    Dim filltext, returntext As String
'    Log("headingline: " & width & "|" & text.Length & "|" & ((width - text.Length)/2) & "|" & Floor((width - text.Length)/2))
    Dim padding As Int = Floor((width - text.Length)/2)
    For x = 1 To padding
        filltext = filltext & fill
    Next
    returntext = filltext & text & filltext
    If returntext.Length < width Then returntext = returntext & fill
    Return returntext.SubString2(0,width)
End Sub

Sub LeftRight(fill As String,leftText As String,rightText As String,width As Int) As String
'    Log("LeftRight: " & width & "|" & leftText.Length & "|" & rightText.Length)
    Dim filltext, returntext As String
    Dim padding As Int = width - leftText.Length - rightText.Length
    For x = 1 To padding
        filltext = filltext & fill
    Next
    returntext = leftText & filltext & rightText
    Return returntext
End Sub

Sub LeftDwRight(fill As String,leftText As String,rightFormat As String,rightText As String,width As Int) As String
    Log("LeftDwRight: " & width & "|" & leftText.Length & "|" & rightText.Length)
    Dim filltext, returntext As String
    Dim padding As Int = width - leftText.Length - rightText.Length
    For x = 1 To padding
        filltext = filltext & fill
    Next
    returntext = leftText & filltext & rightFormat & rightText
    Return returntext
End Sub

Sub leftRightRight(fill As String,leftText As String,middleText As String,rightText As String,middleCol As Int,width As Int) As String
    Dim newleftText, filltext1, filltext2, returntext As String
    Log("leftRightRight: " & leftText.Length &"|"& middleText.Length &"|"& rightText.Length &"|"& middleCol &"|"& width)
    Dim padding1 As Int = middleCol - (leftText.Length + middleText.Length)
    For x = 1 To padding1
        filltext1 = filltext1 & fill
    Next
'    newleftText = leftText & filltext1 & middleText
'    Dim padding2 As Int = width - newleftText.Length
    Dim padding2 As Int = width - (leftText.Length + filltext1.Length + middleText.Length + rightText.Length)
    For x = 1 To padding2
        filltext2 = filltext2 & fill
    Next
    returntext = leftText & filltext1 & middleText & filltext2 & rightText
    Log("leftRightRight: " & width & "|" & leftText.Length & "|" & filltext1.Length & "|" & middleText.Length & "|" & filltext2.Length & "|" & rightText.Length)
    Return returntext
End Sub

Sub leftRightRightRight(fill As String,leftText As String,middleText1 As String,middleText2 As String,rightText As String,middleCol1 As Int,middleCol2 As Int,width As Int) As String
'    Log("leftRightRightRight: " & leftText.Length &"|"& middleText1.Length &"|"& middleText2.Length &"|"& rightText.Length &"|"& middleCol1 &"|"& middleCol2 &"|"& width)
    Dim filltext1, filltext2, filltext3, returntext As String
    Dim padding1 As Int = middleCol1 - leftText.Length - middleText1.Length
    For x = 1 To padding1
        filltext1 = filltext1 & fill
    Next
'    leftText = leftText & filltext1 & middleText1
    Dim padding2 As Int = middleCol2 - (leftText.Length + filltext1.Length + middleText1.Length + middleText2.Length)
    For x = 1 To padding2
        filltext2 = filltext2 & fill
    Next
    
    Dim padding3 As Int = width - (leftText.Length + filltext1.Length + middleText1.Length + filltext2.Length + middleText2.Length + rightText.Length)
    For x = 1 To padding3
        filltext3 = filltext3 & fill
    Next
    Log("leftRightRightRight: " & leftText.Length &"|"& filltext1.Length &"|"& middleText1.Length &"|"& filltext2.Length &"|"& middleText2.Length &"|"& filltext3.Length &"|"& rightText.Length &"|"& middleCol1 &"|"& middleCol2 &"|"& width)
    
    returntext = leftText & filltext1 & middleText1 & filltext2 & middleText2 & filltext3 & rightText
    Return returntext
End Sub
this way I can generate good looking receipts quickly;
receipt:
    inv = headingLine("="," FISCAL INVOICE ",bCols) & CRLF
    inv = inv & LeftRight(" ","TIN:",TIN,bCols) & CRLF
    inv = inv & LeftRight(" ","Company:",Company,bCols) & CRLF
    inv = inv & LeftRight(" ","Store:",Store,bCols) & CRLF
    inv = inv & LeftRight(" ","Address:",Address,bCols) & CRLF
    inv = inv & LeftRight(" ","District:",District,bCols) & CRLF
    inv = inv & LeftRight(" ","Cashier TIN:",UserName,bCols) & CRLF
    inv = inv & LeftRight(" ","POS Number:",InvoiceID,bCols) & CRLF
    inv = inv & LeftRight(" ","POS Time:",InvoiceTS,bCols) & CRLF
    inv = inv & headingLine("-","NORMAL SALE",bCols) & CRLF
    inv = inv & LeftRight(" ","Items"," ",bCols) & CRLF

    inv = inv & headingLine("=","=",bCols) & CRLF
    inv = inv & leftRightRightRight(" ","Name","Price","Qty","Total",16,28,bCols) & CRLF
    inv = inv & LeftRight(" ",ItemName,"",bCols) & CRLF
    inv = inv & leftRightRightRight(" "," ",Round2(ItemPrice,2),ItemQty,Round2(ItemAmount,2),16,28,bCols) & CRLF

    inv = inv & headingLine("-","-",bCols) & CRLF
    inv = inv & LeftRight(" ","Total Purchase:",Round2(ItemAmount,2),bCols) & CRLF
    inv = inv & LeftRight(" ","Payment Method:","Cash",bCols) & CRLF
    inv = inv & headingLine("=","=",bCols) & CRLF
    inv = inv & leftRightRightRight(" ","Label","Name","Rate","Tax",16,28,bCols) & CRLF
    inv = inv & leftRightRightRight(" ","A","VAGST","15.00%",Round2(ItemAmount-(ItemAmount/1.15),2),16,28,bCols) & CRLF

    inv = inv & headingLine("-","-",bCols) & CRLF
    inv = inv & LeftRight(" ","Total Tax:",Round2(ItemAmount-(ItemAmount/1.15),2),bCols) & CRLF
    inv = inv & headingLine("=","=",bCols) & CRLF
    inv = inv & LeftRight(" ","SDC Time:",TIMSts,bCols) & CRLF
    inv = inv & LeftRight(" ","SDC Inv No:",TIMSref&TIMScounter,bCols) & CRLF
    inv = inv & LeftRight(" ","Invoice Counter:",TIMScounter&"/"&TIMScounter&"NS",bCols) & CRLF
    inv = inv & headingLine("=","=",bCols)

sorry about the messy code, but it works for me and I am yet to find a receipt printer that this doesnt work on...

Kev
 

Star-Dust

Expert
Licensed User
Hi, I`m trying to figure out how to print in larger text; has anyone been able to do that?
In the ESC POS commands of the library you will find how to double width and double height, as well as other commands.
B4X:
Printer.AddBuffer_Writeline(ESC.FontA_DoubleHight & "Hallo dear" & ESC_FontA_Normal)
or
B4X:
Printer.AddBuffer_Writeline(ESC.FontA_DoubleOn & "Hallo dear" & ESC_BoldOff)


You should not post sources that do not pertain to the library this THREAD is aimed at. The question was specific to this library, it is not a post on the QUESTION section but a post on the LIBRARY section
You're off the topic. Please stay in the thread topic.
here is my BT Receipt Printer test app adapted from the various published samples for BT, QR Codes and printing.
 

Star-Dust

Expert
Licensed User
Update 0.21
  • Added DiscoveryComplete (Printers As Map)
DiscoveryComplete which will make DiscoveryNewPrinter, DiscoveryFinished and DiscoveryNoDeviceFound unnecessary.

After the search, you can only wait for DiscoveryComplete and it will return a map with the printer name as keys and MacAddr as the value. If the Map is empty it will not have found devices
B4X:
Printer.SearchNewPrinter
   
Wait For Printer_DiscoveryComplete(Printers As Map)
For Each Name As String In Printers.Keys
        Log($"${Name}: ${Printers.Get(Name)}"$)
Next
 
Last edited:
Top