B4A Library ESC/POS Thermal Printer

Hi, I share this ESC/POS Thermal Printer lib, I only tried it with Bluetooth, and to try with USB and TCP and BLE, I didn't have the opportunity to try it, anyway for help https://github.com/DantSu/ESCPOS-ThermalPrinter- Android".
a greeting
 

Attachments

  • ESCPOSThermalPrinter.zip
    22.6 KB · Views: 689
  • Lib.zip
    63.8 KB · Views: 604

amarnath

Member
Licensed User
Longtime User
build tools: 34.0.0, android jar: android-34
Compiling debugger engine code. (8.62s)
Compiling generated Java code. Error
Cannot find: C:\Program Files\Anywhere Software\B4A\libraries\core-3.5.2.jar
 

Xfood

Expert
Licensed User
build tools: 34.0.0, android jar: android-34
Compiling debugger engine code. (8.62s)
Compiling generated Java code. Error
Cannot find: C:\Program Files\Anywhere Software\B4A\libraries\core-3.5.2.jar
try downloading the missing file from here, put it in the additional libraries folder


1730709693872.png
 

Setlodi

Active Member
Hi, roberto64

Thank you for this library. How do you change the width of the paper. It seems to be set for 58mm paper and I want to see if I can use with my printer which is 80mm.

Thanks
 
Last edited:

vecino

Well-Known Member
Licensed User
Longtime User
You don't have to do anything, you can simply write longer lines, instead of:
print(‘123456789*123456789*123456789*12345’)
you can print more:
print(‘123456789*123456789*123456789*123456789*123456789*12345’)
 

roberto64

Active Member
Licensed User
Longtime User
hello everyone, sorry I haven't replied because I had a lot to do. greetings to the whole forum
 

Setlodi

Active Member
Thanks for coming back Roberto.

I have managed to get the printer working and it is printing well, except for centering text. As you can see in the attached images, even your example seems to centering towards the left. Text is centering but it's doing so from the left margin. Would you kindly assist me sort this out.

Header Code:
    sb.Append("[C]<font size='big'>").Append(Report_Business_Name).Append("</font>").Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address1).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address2).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address3).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Phone).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Email).Append(CRLF)

Thank you in advance.

printouts.jpg
 

roberto64

Active Member
Licensed User
Longtime User
Hi, unfortunately I've been very busy lately,
WARNING ⚠ : This tag has several constraints :

A line that contains <img></img> can have only one alignment tag and it must be at the beginning of the line.
<img> must be directly preceded by nothing or an alignment tag ([L][C][R]).
</img> must be directly followed by a new line \n.
You can't write text on a line that contains <img></img>.
Maximum height of printed image is 256px, If you want to print larger bitmap.
 

roberto64

Active Member
Licensed User
Longtime User

Text alignment and column separation​

Add an alignment tag on a same line of text implicitly create a new column.

Column alignment tags :

  • [L] : left side alignment
  • [C] : center alignment
  • [R] : right side alignment
Example :

  • [L]Some text : One column aligned to left
  • [C]Some text : One column aligned to center
  • [R]Some text : One column aligned to right
  • [L]Some text[L]Some other text : Two columns aligned to left. Some other text starts in the center of the paper.
  • [L]Some text[R]Some other text : Two columns, first aligned to left, second aligned to right. Some other text is printed at the right of paper.
  • [L]Some[R]text[R]here : Three columns.
  • [L][R]text[R]here : Three columns. The first is empty but it takes a third of the available space.
 

Setlodi

Active Member
Thanks for your response Roberto

In my code I have only 1 column that I'm trying to centre right. Is there anything that is missing from my code?

B4X:
    sb.Append("[C]<font size='big'>").Append(Report_Business_Name).Append("</font>").Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address1).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address2).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address3).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Phone).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Email).Append(CRLF)
 

f0raster0

Well-Known Member
Licensed User
Longtime User
Thanks for your response Roberto

In my code I have only 1 column that I'm trying to centre right. Is there anything that is missing from my code?

B4X:
    sb.Append("[C]<font size='big'>").Append(Report_Business_Name).Append("</font>").Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address1).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address2).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Address3).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Phone).Append(CRLF)
    sb.Append("[C]").Append(Report_Business_Email).Append(CRLF)
sb.Append("[R]")
 

roberto64

Active Member
Licensed User
Longtime User
Hi, it's been a long time since I've seen this library, anyway sb.Append("[R]").Append("Title").Append(CRLF)
 

Setlodi

Active Member
Still no luck:

Header:
    sb.Append("[R]<b><font size='big'>").Append(Receipt_Business_Name).Append("</font></b>").Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Address1).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Address2).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Address3).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Phone).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Email).Append(CRLF)

    sb.Append("[R]").Append(Receipt_Message1).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Messaage2).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Message3).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Message4).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Mess[ATTACH]160983[/ATTACH][ATTACH]160983[/ATTACH]age5).Append(CRLF)
 

Attachments

  • Till slip.png
    Till slip.png
    280.7 KB · Views: 157

nakuable

Member
Dear friends, I'm trying use this library, but i can't get the printer to print.

Heare is a little part of my implamentation:
B4X:
                Private rp As RuntimePermissions
                rp.CheckAndRequest("android.permission.BLUETOOTH_CONNECT")

                ' Inicializar admin y serial
                admin.Initialize("admin")
                serial.Initialize("serial")

                ' Conectar a la impresora
                serial.Connect("03:02:9C:C1:2C:7F")
                Log("Conexión establecida")
                AStreamI.InitializePrefix(serial.InputStream, True, serial.OutputStream, "AStreamI")
                Wait For Serial_Connected (Success As Boolean)

                If Success Then
                    Log("Conexión correcta con impresora")
                    Sleep(5000) ' Dale un pequeño respiro a la impresora
                    escpo.doPrintBluetoot("Mi Primera Impresión")
                    escpo.doPrintBluetoot("Y la segunda")
                    Log("Imprimo!!")
                Else
                    Log("Fallo al conectar con la impresora")
                End If

About the code, I get the Log "Conexión correcta con impresora" in to, If Success Then because Success is True.

Note that i can't use B4x Pages in my project, because the app is big and developed with out it. And is so time expensive implement right now.

I think that is mandatary use B4x Pages, but i don't know.

Please, help me.

Thank you very much in advance.
 

roberto64

Active Member
Licensed User
Longtime User
Hi, if I remember, what I can tell you is that to connect with Bluetooth you have to use the library function to connect to Bluetooth
 

Theera

Expert
Licensed User
Longtime User
Still no luck:

Header:
    sb.Append("[R]<b><font size='big'>").Append(Receipt_Business_Name).Append("</font></b>").Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Address1).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Address2).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Address3).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Phone).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Business_Email).Append(CRLF)

    sb.Append("[R]").Append(Receipt_Message1).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Messaage2).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Message3).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Message4).Append(CRLF)
    sb.Append("[R]").Append(Receipt_Mess[ATTACH]160983[/ATTACH][ATTACH]160983[/ATTACH]age5).Append(CRLF)
Could you share your the example code for studying,please?
 

nakuable

Member
Hi, if I remember, what I can tell you is that to connect with Bluetooth you have to use the library function to connect to Bluetooth
Hi roberto64, thank you very much for your reply.

I rechecked the code of app example, and I can't see any function to connect to BLE.

I only see escpo.connectiontUsb but, I have commented in my example code and is running and printer print.

I continue analyzing the issue, if any peopple can help me. Thank you very much in advance.
 
Top