Flutter Bluetooth printing to Zebra

1,391

I ended up creating my own plugin.

source code

EDIT: 2021/11/29 integrate some comments from comments section

  1. This code is not limited to zpl. In theory it can support every printer language that sends clear text to bluetooth serial

  2. It is only for Android

  3. For this source code to works as is:

  • You have to pair a bluetooth printer with name that starts with "zebra"
  • You have to send the zpl commands as string.
  1. The easiest way to check that your zpl command is valid, is by using the ultra useful labelary viewer. The easiest way to test a label layout (font size, images, barcodes etc) is by using the above free service. in fact all you have to do, is to create the layout you need in labelary and the just copy the entire string from first ^XA to last ^XZ to FlutterCblue.printToBT. For example if you send this
printToBT("^XA

^FX Top section with logo, name and address.
^CF0,60
^FO50,50^GB100,100,100^FS
^FO75,75^FR^GB100,100,100^FS
^FO93,93^GB40,40,40^FS
^FO220,50^FDIntershipping, Inc.^FS
^CF0,30
^FO220,115^FD1000 Shipping Lane^FS
^FO220,155^FDShelbyville TN 38102^FS
^FO220,195^FDUnited States (USA)^FS
^FO50,250^GB700,3,3^FS

^FX Second section with recipient address and permit information.
^CFA,30
^FO50,300^FDJohn Doe^FS
^FO50,340^FD100 Main Street^FS
^FO50,380^FDSpringfield TN 39021^FS
^FO50,420^FDUnited States (USA)^FS
^CFA,15
^FO600,300^GB150,150,3^FS
^FO638,340^FDPermit^FS
^FO638,390^FD123456^FS
^FO50,500^GB700,3,3^FS

^FX Third section with bar code.
^BY5,2,270
^FO100,550^BC^FD12345678^FS

^FX Fourth section (the two boxes on the bottom).
^FO50,900^GB700,250,3^FS
^FO400,900^GB3,250,3^FS
^CF0,40
^FO100,960^FDCtr. X34B-1^FS
^FO100,1010^FDREF1 F00B47^FS
^FO100,1060^FDREF2 BL4H8^FS
^CF0,190
^FO470,955^FDCA^FS

^XZ")

You will get this:

You will get this:

One more thing: keep in mind that if you want to print special language characters (I need to print Greek) you have to find the correct font that is installed in your printer. For example: In order to print Greek characters I have to integrate this

^CWN,E:TT0003M_.FNT

just after the first ^XA. Then I use the N font in order to print Greek. It is very flexible if you understand the basics

Hope it helps

Share:
1,391
John Anderton
Author by

John Anderton

Full Stack developer for more than 15 years. MCT .net since 2005. Now committed on Django, Vue.js and Flutter

Updated on December 16, 2022

Comments

  • John Anderton
    John Anderton over 1 year

    I need to add printing functionality on a zebra zq520 bluetooth thermal printer. I manage to do so using the flutter_blue plugin but I am not happy with the implementation. I hate to break the string to smaller chunks in order to pass through bluetooth (and wait!!!!!). I was wondering if there is a better approach, like the one we used in the (good?) old days of java for android using the android.bluetooth.BluetoothAdapter class

    Thanks.

  • John Anderton
    John Anderton over 3 years
    I upload the code here for everyone interest: stackoverflow.com/a/63013581/12009639
  • Rakesh
    Rakesh over 2 years
    could you please share the source code , this link is failing to load .. I am having the similar problem please help
  • John Anderton
    John Anderton over 2 years
    @Rakesh Yes of course. I edited my first answer
  • Rakesh
    Rakesh over 2 years
    Are you sending ZPL text to the printer or the normal text ?
  • John Anderton
    John Anderton over 2 years
    @Rakesh zpl. check if it is valid with labelary.com
  • Rakesh
    Rakesh over 2 years
    Anyway to get the paired device using this method , printer is not showing while searching it
  • John Anderton
    John Anderton over 2 years
    @Rakesh it needs a printer with name that starts with “zebra” eg zebra10, zebra11 etc
  • OguzKaanAkyalcin
    OguzKaanAkyalcin over 2 years
    Thanks, @John Anderton. I guess your source code is the only working sample for zebra printers. but the size of the letters is really small, how did you fix that? ( stackoverflow.com/questions/70143161/… )
  • John Anderton
    John Anderton over 2 years
    @OguzKaanAkyalcin please check zpl manual. It’s all there, nothing to do with my code. For your convenience you can use the (excellent and free) labelary viewer online. They also have a very nice sample zpl code that answers your question about the font size. And one more thing; my code in theory is global, meaning every Bluetooth printer and every language can used. Not limited to zpl. Never checked it though.
  • Nirav Patel
    Nirav Patel over 2 years
    @Rakesh did you find anything that prints labels in Flutter?
  • Rakesh
    Rakesh over 2 years
    @NiravPate Yes , I have send command in ZPL format the it got worked
  • Nirav Patel
    Nirav Patel over 2 years
    @Rakesh Possible for you to give one sample demo for that? It would be really a great help.
  • John Anderton
    John Anderton over 2 years
    @NiravPatel I have a fully working demo above. You can use that. You don’t need anything more that that. The code works out of the box. Follow the instructions from the above answer