B4J Library [B4X] SD Zebra (printer)

This library is the result of my first approach with Zebra printers. I started by connecting via LAN (or Wi-Fi) ZPL language.
I plan to connect via BLE and perhaps also via USB. Have a good time. Preview only works if you have an internet connection
For ESC/POS Printer see here
The Demo version does not print images, barcodes, raw commands

NB
: This is a demo version, each print will show the SD symbol. Contact me privately for a full version.
Some Honeywell printers support the ZPL II language to make them compatible with Zebra and facilitate replacement. So this library might work on Honeywell as well



Anyone who wants a different version from those distributed (such as Bluetooth SPP, USB, RS) can contact me privately.
OS
Bluetooth SPP
BLE (Beacon)
USB
LAN / WIFI
RS 232
NFC
Android​
x (On request)​
x​
x (on request)​
x​
iOs​
x​
x​
Window​
x (On request)​
x​
x​



aSD_Zebra

Author:
Star-Dust
Version: 1.11
  • BLEZebraPrinter
    • Events:
      • BLEisOFF
      • Connected (services As List)
      • Disconnected
      • ImageWriteComplete
      • PrinterFound (Name As String, ID As String)
      • StateChanged (msg As String)
      • WriteComplete (Characteristic As String, Success As Boolean)
    • Fields:
      • CharatteristicName As String
      • currentState As Int
      • Encoding As String
      • Rotate180 As String
      • Rotate270 As String
      • Rotate90 As String
      • RotateNormal As String
      • ServiceName As String
    • Functions:
      • Active (CodeActivation As String) As String
      • AddBarCode (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        CODE 128
        Zebra.AddBarCode(50,50,"1234567890",5)
      • AddBarCodeEAN13 (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        EAN13
        Zebra.AddBarCodeEAN13(50,50,"1234567890",5)
      • AddCircle (X As Int, Y As Int, radius As Int, StrokeWidth As Int, Filled As Boolean) As String
        Zebra.AddCircle(50,50,25,3,false)
      • AddHorizLine (X As Int, Y As Int, Width As Int, StrokeWidth As Int) As String
        Zebra.AddHorizLine(50,50,700,3)
      • AddImage (X As Int, Y As Int, bmp As B4XBitmap) As String
        Zebra.AddImage() ' not active
      • AddLogoSD (X As Int, Y As Int)
        Add logo SD to coordinate
      • AddQRcode (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        Zebra.AddQRcode(50,50,"1234567890",5)
      • AddRaw (Text As String) As String
      • AddRectangle (X As Int, Y As Int, Width As Int, Height As Int, StrokeWidth As Int, Filled As Boolean, InvertBrush As Boolean) As String
        Zebra.AddRectangle(50,50,100,100,3,false,false)
      • AddRectangleRounded (X As Int, Y As Int, Width As Int, Height As Int, StrokeWidth As Int, Filled As Boolean, Rounded As Int) As String
        Zebra.AddRectangleRounded(50,50,100,100,3,false,5)
      • AddText (X As Int, Y As Int, Text As String, TextSize As Int, Bold As Boolean) As String
        Zebra.AddText(50,50,"Text",50, false)
      • AddTextRotate (X As Int, Y As Int, Text As String, TextSize As Int, Bold As Boolean, Rotation As String) As String
        Zebra.AddTextRotate(50,50,"Text",50, false,Zebra.RotateNormal)
        Zebra.AddTextRotate(50,50,"Text",50, false,Zebra.Rotate90)
      • AddVertLine (X As Int, Y As Int, Height As Int, StrokeWidth As Int) As String
        Zebra.AddVertLine(400,100,300,3)
      • Class_Globals As String
      • Connect (ID As String) As String
        CharatteristicName = "2AF0" or "2AF1"
      • Disconnect As String
      • Initialize (CallBack As Object, EventName As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • Preview As String
        Evito di usare okHttpUtils
      • Print As String
      • ScanPrinter As String
      • StopScanning As String
    • Properties:
      • isConnect As Boolean [read only]
      • isScanning As Boolean [read only]
      • LabelWidth
      • Raw As String [read only]
      • BlackRange
  • LanZebraPrinter
    • Events:
      • Opened (Success As Boolean)
      • Preview (Success As Boolean, bmp As B4XBitmap)
    • Fields:
      • desktop As Int
      • Encoding As String
      • Mobile As Int
      • Rotate180 As String
      • Rotate270 As String
      • Rotate90 As String
      • RotateNormal As String
    • Functions:
      • Active (CodeActivation As String) As String
      • AddBarCode (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        Code 128
        Zebra.AddBarCode(50,50,"1234567890",5)
      • AddBarCodeEAN13 (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        EAN13
        Zebra.AddBarCodeEAN13(50,50,"1234567890",5)
      • AddBarCodeEAN8 (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        EAN8
        Zebra.AddBarCodeEAN8(50,50,"1234567890",5)
      • AddCircle (X As Int, Y As Int, radius As Int, StrokeWidth As Int, Filled As Boolean) As String
        Zebra.AddCircle(50,50,25,3,false)
      • AddHorizLine (X As Int, Y As Int, Width As Int, StrokeWidth As Int) As String
        Zebra.AddHorizLine(50,50,700,3)
      • AddImage (X As Int, Y As Int, bmp As B4XBitmap) As String
        Zebra.AddImage() ' not active
      • AddLogoSD (X As Int, Y As Int)
        Add logo SD to coordinate
      • AddQRcode (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        Zebra.AddQRcode(50,50,"1234567890",5)
      • AddRaw (Text As String) As String
      • AddRectangle (X As Int, Y As Int, Width As Int, Height As Int, StrokeWidth As Int, Filled As Boolean, InvertBrush As Boolean) As String
        Zebra.AddRectangle(50,50,100,100,3,false,false)
      • AddRectangleRounded (X As Int, Y As Int, Width As Int, Height As Int, StrokeWidth As Int, Filled As Boolean, Rounded As Int) As String
        Zebra.AddRectangleRounded(50,50,100,100,3,false,5)
      • AddText (X As Int, Y As Int, Text As String, TextSize As Int, Bold As Boolean) As String
        Zebra.AddText(50,50,"Text",50, false)
      • AddTextRotate (X As Int, Y As Int, Text As String, TextSize As Int, Bold As Boolean, Rotation As String) As String
        Zebra.AddTextRotate(50,50,"Text",50, false,Zebra.RotateNormal)
        Zebra.AddTextRotate(50,50,"Text",50, false,Zebra.Rotate90)
      • AddVertLine (X As Int, Y As Int, Height As Int, StrokeWidth As Int) As String
        Zebra.AddVertLine(400,100,300,3)
      • Class_Globals As String
      • Clear As String
      • Close As String
      • Initialize (Callback As Object, Event As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • Open (Host As String, TypePrinter As Int) As String
        Zebra.Open("192.168.1.202",Zebra.desktop)
      • Preview As String
        Evito di usare okHttpUtils
      • Print As String
      • PrintAndClose
    • Properties:
      • LabelWidth
      • Raw As String [read only]
      • BlackRange
  • UsbZebraPrinter
    Ctrl + click to build b4xlib: ide://run?file=%JAVABIN%\jar.exe&WorkingDirectory=%PROJECT%\..&Args=-cMf&Args=%PROJECT_NAME%.b4xlib&&Args=..&Args=*.bas&Args=manifest.txt
    preview http://labelary.com/viewer.html
    • Events:
      • Opened (Success As Boolean)
      • Preview (Success As Boolean, bmp As B4XBitmap)
    • Fields:
      • desktop As Int
      • Encoding As String
      • Mobile As Int
      • Rotate180 As String
      • Rotate270 As String
      • Rotate90 As String
      • RotateNormal As String
    • Functions:
      • Active (CodeActivation As String) As String
      • AddBarCode (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        Code 128
        Zebra.AddBarCode(50,50,"1234567890",5)
      • AddBarCodeEAN13 (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        EAN13
        Zebra.AddBarCodeEAN13(50,50,"1234567890",5)
      • AddBarCodeEAN8 (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        EAN8
        Zebra.AddBarCodeEAN8(50,50,"1234567890",5)
      • AddCircle (X As Int, Y As Int, radius As Int, StrokeWidth As Int, Filled As Boolean) As String
        Zebra.AddCircle(50,50,25,3,false)
      • AddHorizLine (X As Int, Y As Int, Width As Int, StrokeWidth As Int) As String
        Zebra.AddHorizLine(50,50,700,3)
      • AddImage (X As Int, Y As Int, bmp As B4XBitmap) As String
        Zebra.AddImage() ' not active
      • AddLogoSD (X As Int, Y As Int)
        Add logo SD to coordinate
      • AddQRcode (X As Int, Y As Int, Height As Int, Code As String, Size As Int) As String
        Zebra.AddQRcode(50,50,"1234567890",5)
      • AddRaw (Text As String) As String
      • AddRectangle (X As Int, Y As Int, Width As Int, Height As Int, StrokeWidth As Int, Filled As Boolean, InvertBrush As Boolean) As String
        Zebra.AddRectangle(50,50,100,100,3,false,false)
      • AddRectangleRounded (X As Int, Y As Int, Width As Int, Height As Int, StrokeWidth As Int, Filled As Boolean, Rounded As Int) As String
        Zebra.AddRectangleRounded(50,50,100,100,3,false,5)
      • AddText (X As Int, Y As Int, Text As String, TextSize As Int, Bold As Boolean) As String
        Zebra.AddText(50,50,"Text",50, false)
      • AddTextRotate (X As Int, Y As Int, Text As String, TextSize As Int, Bold As Boolean, Rotation As String) As String
        Zebra.AddTextRotate(50,50,"Text",50, false,Zebra.RotateNormal)
        Zebra.AddTextRotate(50,50,"Text",50, false,Zebra.Rotate90)
      • AddVertLine (X As Int, Y As Int, Height As Int, StrokeWidth As Int) As String
        Zebra.AddVertLine(400,100,300,3)
      • Class_Globals As String
      • Clear As String
      • getRaw As String
      • Initialize (Callback As Object, Event As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • Preview As String
        Evito di usare okHttpUtils
      • Print (printer As String) As String
      • PrintAndClose (printer As String) As String
      • setLabelWidth (Width As Int) As String
    • Properties:
      • LabelWidth
      • Raw As String [read only]
      • BlackRange



Update log
  • 1.01
    • Added printer type parameter on the Open method. It can be desktop or mobile printer
    • Added AddTextRotate command. Enter constants to pass as parameter (RotateNormal, Rotate90, Rotate180, Rotate270)
  • 1.02 Added method AddImage
  • 1.03 Fix bugs
  • 1.05 Added class for printing with BLE (BLE Not available for B4J)
  • 1.06 Fix bugs
  • 1.07 Added AddBarCodeEAN13 method
  • 1.08 Added AddBarCodeEAN8 method and Fix Bug
  • 1.09 Fix Bugs on authentication and streaming channel
  • 1.10 Added USB communication in B4J version, Fix bugs QR code
  • 1.11 Added AddLogoSD and BlackRange (Limit for the transformation between color and black and white images))
 

Attachments

  • jSD_Zebra 1.11.zip
    21.9 KB · Views: 274
  • aSD_Zebra 1.11.zip
    24.3 KB · Views: 303
  • iSD_Zebra 1.11.zip
    223.9 KB · Views: 262
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Example LAN

B4X:
Sub Button1_Click
    Dim Zebra As LanZebraPrinter
    Zebra.Initialize(Me,"Zebra")
 
    Zebra.AddText(240,50,"Intershipping, Inc.",60,True)
    Zebra.AddText(240,115,"1000 Shipping Lane",30,True)
    Zebra.AddText(240,155,"Shelbyville TN 38102",30,True)
    Zebra.AddText(240,195,"United States (USA)",30,True)
    Zebra.AddHorizLine(50,250,700,3)
    Zebra.AddBarCode(50,300,200,"123456789",3)
 
    Zebra.Open(TextHost.Text,Zebra.desktop)
    Wait For Zebra_Opened(Success As Boolean)
    If Success Then Zebra.PrintAndClose
End Sub

Private Sub Button2_Click
    Dim Zebra As LanZebraPrinter
    Zebra.Initialize(Me,"Zebra")
 
    Zebra.AddText(240,50,"Intershipping, Inc.",60,True)
    Zebra.AddText(240,115,"1000 Shipping Lane",30,True)
    Zebra.AddText(240,155,"Shelbyville TN 38102",30,True)
    Zebra.AddText(240,195,"United States (USA)",30,True)
    Zebra.AddHorizLine(50,250,700,3)
    Zebra.AddBarCode(50,300,200,"123456789",3)

    Zebra.Preview ' Requires an internet connection
    Wait For Zebra_Preview(Success As Boolean, bmp As B4XBitmap)
    If Success Then ImageView1.SetBitmap(bmp.Resize(ImageView1.Width,ImageView1.Height,True))
 
    Sleep(100)
    Zebra.Close
End Sub

Example BLE
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
 
    Private ZebraBLE As BLEZebraPrinter
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
 
    ZebraBLE.Initialize(Me,"ZebraBLE")
End Sub

Private Sub ButtonSearchBLE_Click
    ZebraBLE.ScanPrinter
End Sub

Private Sub ZebraBLE_PrinterFound(Name As String, ID As String)
    Log(Name)
    ZebraBLE.CharatteristicName="2AF1" ' Print Service
    ZebraBLE.Connect(ID)
End Sub

Private Sub ZebraBLE_Connected(services As List)
    ZebraBLE.AddText(40,40, "Test to print",40,True)
    ZebraBLE.Print
End Sub

For an example to print PDF files see here


ExampleUSB
B4X:
Dim Zebra As UsbZebraPrinter
Zebra.Initialize(Me,"Zebra")
Zebra.AddText(240,50,"Intershipping, Inc.",60,True)
Zebra.AddHorizLine(50,250,700,3)
Zebra.AddBarCode(50,300,200,"123456789",3)
  
Zebra.Print("ZEBRA PRINTER NAME")
ZEBRA USB for B4J
Note: In order to use the library (B4J) to print with zebra, the printer driver must be installed on the PC
 

Attachments

  • aSample.zip
    9.7 KB · Views: 339
  • jSample.zip
    2.6 KB · Views: 327
  • iSample.zip
    3 KB · Views: 305
  • jSD_Zebra USB.zip
    2.5 KB · Views: 216
Last edited:

Sandman

Expert
Licensed User
Longtime User
Let me see if I understood this correctly. You created a new thread where you reserved the first post!? :D

I don't think you should worry, it's not like Erel has put a hard limit on amount of threads that can be created during his vacation. :)
 

Star-Dust

Expert
Licensed User
Longtime User
Let me see if I understood this correctly. You created a new thread where you reserved the first post!? :D

I don't think you should worry, it's not like Erel has put a hard limit on amount of threads that can be created during his vacation. :)
Are you sure? ?
 

Star-Dust

Expert
Licensed User
Longtime User
iOs version released and examples updated.

Thanks @Erel that despite being on vacation has enabled me to compile the ios library
 
Last edited:

Leandro Vaufran Stievano

Member
Licensed User
240.115",
Exemplo

[CÓDIGO=b4x]
Subbotão1_Clique
Dim Zebra como LanZebraPrinter
Zebra.Initialize(Me,"Zebra")

Zebra.AddText(240,50,"Intershipping, Inc.",60,True)
Zebra.AddText(240,115,"1000 Rota de Envio",30,True)
Zebra.AddText(240,155,"Shelbyville TN 38102",30,True)
Zebra.AddText(240,195,"Estados Unidos (EUA)",30,True)
Zebra.AddHorizLine(50.250.700,3)
Zebra.AddBarCode(50.300.200,"123456789",3)

Zebra.Open(TextHost.Text)
Aguarde Zebra_Opened(Sucesso como booleano)
Se for sucesso, então Zebra.PrintAndClose
Finalizar Sub

Botão de subscrição privada2_Click
Dim Zebra como LanZebraPrinter
Zebra.Initialize(Me,"Zebra")

Zebra.AddText(240,50,"Intershipping, Inc.",60,True)
Zebra.AddText(240,115,"1000 Rota de Envio",30,True)
Zebra.AddText(240,155,"Shelbyville TN 38102",30,True)
Zebra.AddText(240,195,"Estados Unidos (EUA)",30,True)
Zebra.AddHorizLine(50.250.700,3)
Zebra.AddBarCode(50.300.200,"123456789",3)

Zebra.Visualizar
Aguarde Zebra_Preview (Sucesso como booleano, bmp como B4XBitmap)
Se for bem-sucedido, então ImageView1.SetBitmap(bmp.Resize(ImageView1.Width,ImageView1.Height,True))

Dormir(100)
Zebra. Fechar
Fim Sub[/CODE]
Fantastic !
Is there any possibility to adapt the Lib to Argox OS-214 USB printers?
 

micro

Well-Known Member
Licensed User
Longtime User
Hi Star
The Preview function need an internet connection or does it use the offline server?
Thanks
 

Star-Dust

Expert
Licensed User
Longtime User
Hi Star
The Preview function need an internet connection or does it use the offline server?
Thanks
Requires an internet connection. I will specify this in the first post
 

micro

Well-Known Member
Licensed User
Longtime User
Requires an internet connection. I will specify this in the first post
okay, as I did in the tests, I thought you were using the offline server that Omar shared (at least I think it's an offline server)
Great job Star
 

Star-Dust

Expert
Licensed User
Longtime User
okay, as I did in the tests, I thought you were using the offline server that Omar shared (at least I think it's an offline server)
Great job Star
it would be a great idea to have it offline, but I don't have time to study how.

Thank
 

Star-Dust

Expert
Licensed User
Longtime User
Update rel. 1.01

  • Added printer type parameter on the Open method. It can be desktop or mobile printer.
    B4X:
    Zebra.Open(TextHost.Text,Zebra.desktop)
  • Added AddTextRotate command. Enter constants to pass as parameter (RotateNormal, Rotate90, Rotate180, Rotate270)
    B4X:
     Zebra.AddTextRotate (240,50,"Intershipping, Inc.",60,True,Zebra.Rotate90)
  • Updated examples
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
good job, USB0.98 'UsbManager can get USBDisk,but i dont kown how to copy file to insideCard,can you help me ?
I'm sorry I don't understand what you are asking. If it is a question that does not concern this library write it in a post in the questions section and not in this thread
 

byz

Active Member
Licensed User
I'm sorry I don't understand what you are asking. If it is a question that does not concern this library write it in a post in the questions section and not in this thread
i have Solve that problem。
I'm Chinese and my English is not very good. Some expressions may not be clear. excuse me.
 

Star-Dust

Expert
Licensed User
Longtime User
ANNOUNCEMENTS
I have completed the function to print images. See you soon an update.
 

Star-Dust

Expert
Licensed User
Longtime User
PDF TO ZEBRA
I am attaching a new cross-platform example (B4XPage) that allows you to print a PDF file. For each version, a PDF library must be downloaded.

For B4J it is necessary to download this jar JAR
- https://www.apache.org/dyn/closer.lua/pdfbox/2.0.26/pdfbox-app-2.0.26.jar
(see also https://www.b4x.com/android/forum/t...-show-pdf-document-in-b4j.103350/#post-647789)

For B4A you need to download this library
- https://www.b4x.com/android/forum/threads/pdfrenderer-v0-10-beta-create-your-own-pdf-viewer.49103/

For B4I no additions
 

Attachments

  • PDFtoZebra.zip
    198.8 KB · Views: 288
Last edited:

imbault

Well-Known Member
Licensed User
Longtime User
Good work @Star-Dust , do you know when it will be possible to communicate in BT or BLE (better), as I need to work with mobile Zebra devices

Thanks
 

Star-Dust

Expert
Licensed User
Longtime User
Good work @Star-Dust , do you know when it will be possible to communicate in BT or BLE (better), as I need to work with mobile Zebra devices

Thanks
I am working for BLE and USB. I already have the classes ready but I have to do the tests and I don't have a printer.

Trying ESC / POS printers the BLE and USB connection works, so I'm very confident it works on ZEBRA too
 
Last edited:
Top