13 Replies Latest reply on Sep 6, 2018 7:27 AM by andrea schiabel

    B64 or Z64 with Zebra SDK ??

    daniel Ppe


      How to get B64 or Z64 and CRC with the SDK Zebra(android) to print with zpl with this command:


      ~DYE:IMAGE,P,P,46080,46080,:B64:  .......






      Thank you very much!!

        • Re: B64 or Z64 with Zebra SDK ??
          Robin West

          Hi Daniel,

          You wouldn't need to do any of the conversion yourself.  Just use the printer.printImage() or printer.storeImage() API's.  They take PNG, JPG, and BMP file formats.

          Link-OS SDK - Zebra Technologies Techdocs  - look at the GraphicsUtil class for some sample code.

          1 of 1 people found this helpful
            • Re: B64 or Z64 with Zebra SDK ??
              daniel Ppe

              Thank you very much I have worked!

              Just one last question, how do I get it into zpl?

              What is the ZPL command to display it there ....



              Thank you!!!

                • Re: B64 or Z64 with Zebra SDK ??
                  Robin West

                  Hi Daniel, You can use the storeImage() command before sending the zpl and then use the ^FO in combination with the ^IM command to modify the location in your ZPL:





                  X and Y coordinates are generally for the top left corner of the image.


                  Or you can use the printImage() inside format to place it.

                  String zplStart = "^XA...";

                  String zplEnd = "...^XZ";


                  printer.printImage("myImage.png", 10, 608, 0, 0, true);



                  I can't give you specifics for the X and Y locations because I don't know how big your receipt is, or exactly how far down the page it is.

                  1 of 1 people found this helpful
                • Re: B64 or Z64 with Zebra SDK ??
                  Tim Borowsky

                  Hello Robin,


                  Is there a B64 algorithm in an SDK for the .NET Framework? I require it for some software I am developing.




                    • Re: B64 or Z64 with Zebra SDK ??
                      Robin West

                      Hi Tim, Sorry this is coming to you so late, but it might help others who need it.  The Zebra .Net SDK has a ConvertGraphic() function to convert an image into a B64 encoded PNG image. You can use this without ever opening the connection to a printer.  It does add a ZPL download header, but you can remove it by searching for the string ":B64:" and removing everything before that.  The filePathOnPrinter must have the PNG extension to convert to a B64 image.


                      MemoryStream ms = new MemoryStream();
                      ZebraImageI image = ZebraImageFactory.GetImage(pathOnComputer);
                      PrinterUtil.ConvertGraphic("E:IMAGE.PNG", image, ms);
                      ms.Write(buffer, 0, ms.Length);

                      There are also likely 3rd party libraries to do this.

                        • Re: B64 or Z64 with Zebra SDK ??
                          andrea schiabel

                          Hi Robin.


                          I'm trying to have a ZPL code from a JPG image ....but the result of the ConvertGraphic funciton is not correctly printed by our Zebra ZT230.


                          These are the few code lines (Vb.Net - I wrote the ZPL in a file):

                                  Dim Fs As System.IO.FileStream

                                  Dim Ms As New System.IO.MemoryStream

                                  Dim Im As Sdk.Graphics.ZebraImageI

                                  Im = ZebraImageFactory.GetImage("C:\Zebra\150_00_00_02.jpg")

                                  Sdk.Printer.PrinterUtil.ConvertGraphic("c:\Zebra\IMAGE.PNG", Im, 20, 20, Ms)

                                  Fs = New IO.FileStream("C:\Zebra\ZPL.txt", IO.FileMode.Create)



                          I tried to put the result of the ZPL.txt file after the ZPL command ^GFA ....but I don't know how to set the three parameters of the ^GF command ....and ....in any case the image printed is not the same as the source jpg.


                          Where I go wrong ?


                          Thank you in advance !

                            • Re: B64 or Z64 with Zebra SDK ??
                              Diego Gonzalez

                              Hello Andrea,


                              Not sure if this helps with your GF command issue, but to get the ZPL you need to reset the memory stream position to 0 as follows (in C#):


                              using (var ms = new MemoryStream())
                              using (var rd = new StreamReader(ms))
                                  var image = ZebraImageFactory.GetImage("myPng.png");
                                  PrinterUtil.ConvertGraphic("E:IMAGE.PNG", image, ms);
                                  ms.Position = 0; // memory stream position is at the end, as we just wrote to it: set position back to beginning
                                  var text = rd.ReadToEnd();
                                  Console.WriteLine(text); // -> ZPL: remove header (and maybe suffix?) as Robin proposed


                              Hope this helps!



                                • Re: B64 or Z64 with Zebra SDK ??
                                  andrea schiabel

                                  Thank you Diego for your help !!

                                  The issue is NOT the stream reading .....but the value of the string that the ReadToEnd returns !!

                                  If I put the result in a ZPL viewer it doesn't show me the original picture.

                                  The ZPL viewer doesn't give me an error....simply shows a kind of "qr-code picture".


                                  Maybe the issue is because of the ":B64:" starting string (instead of Z64).



                                    • Re: B64 or Z64 with Zebra SDK ??
                                      Diego Gonzalez


                                      For me with a PNG file (no transparency) it is working as follows, once you did the read to end:

                                      Calling the method to get ZPL:


                                      var zpl = GetImgZpl(text);


                                      The method:


                                      private string GetImgZpl(string imgTxt)
                                          return "^XA"
                                              + "~" + imgTxt
                                              + "^FO70,70^IME:IMAGE.PNG^FS"
                                              + "^IDE:IMAGE.PNG"
                                              + "^XZ";


                                      Generated ZPL:


                                      ~ DYE:IMAGE p p 2764  :B64:iVBORw0KGgoAA (lots of characters...) LzRYWmUgMAAAAASUVORK5CYII=:e11c


                                      This ZPL is sent to the printer and works fine. There are some escaped characters in the formatting above, but the point is that I just get the command as it is returned by PrinterUtil method without any additional processing. The ZPL loads the image in the printer, prints it, then delete from memory (E:).


                                      Good luck,