5 Replies Latest reply on Jul 19, 2018 8:42 AM by Jim Jensen

    iMZ320/ZPL: How to use Z64 and LZ77 to compress data downloading to the printer

    Hartmut Neubauer

      Hi, I have an iMZ320 8cm printer and I want to use it with Android devices. Usually we transform all our print data to graphics and send them to the printer; this works in our case (using ^GF for every graphics field), but it needs too much time to download all the data. Currently I use ASCII encoding with Base64 (for example: "^GFA,1152,1152,72,:B64:AAADwAAAA+AAA<.....>AAA:f113") So I thought to use compression. There is the possibility of LZ77 compression before the Base64 encoding (something like that: "^GFA,1152,1152,75,:Z64:xxxxxx:crcc").

      Can anybody assist me how to implement the LZ77 algorithm? Thanks in advance.

        • Re: iMZ320/ZPL: How to use Z64 and LZ77 to compress data downloading to the printer
          Manuel Caicedo-Rivera

          Hi Hartmut,


          If you want to work with Android Devices, we have a powerful set of libraries, classes and interfaces that you can use immediately in your project.

          For the specific use case mentioned, Zebra's API has already implemented the Z64 compression algorithm.


          Zebra API for Android (build v2.9.2275)

          I have a sample code that you can use.


          public interface GraphicsUtil


          This is an utility class for printing images on a device.


          package test.zebra.sdk.printer.examples;


          import java.io.IOException;


          import com.zebra.sdk.comm.Connection;

          import com.zebra.sdk.comm.ConnectionException;

          import com.zebra.sdk.comm.TcpConnection;

          import com.zebra.sdk.printer.ZebraPrinter;

          import com.zebra.sdk.printer.ZebraPrinterFactory;

          import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;


          public class GraphicsUtilExample {


               public static void main(String[] args) throws Exception {

                   Connection connection = new TcpConnection("", TcpConnection.DEFAULT_ZPL_TCP_PORT);

                   try {


                       ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);

                       int x = 0;

                       int y = 0;

                       printer.printImage("/sdcard/sample.jpg", x, y);

                   } catch (ConnectionException e) {


                   } catch (ZebraPrinterLanguageUnknownException e) {


                   } catch (IOException e) {


                   } finally {







          We highly recommend to avoid send a huge quantity of data during WiFi or BT connection, please, take a look to our article

          Zebra Technologies - Best Practices in Creating a Printing Application for Zebra Printers


          We recommend Zebra Designer tool to build your label, this tool will generate the code in ZPL for you, then you can use it in your app.


          Please, let me know if you need more assistance.




            • Re: iMZ320/ZPL: How to use Z64 and LZ77 to compress data downloading to the printer
              Hartmut Neubauer

              Hi Manuel,


              thank you very much for your contribution.


              I have now downloaded the SDK and I am trying to use it. My purpose is the following which I have seen that it is very useful; it works yet without SDK, simply with ZPL.


              Because, how we have yet stated, transmitting big graphic data is very time-consuming, I have seen that it is very useful first to separate our labels in fixed and variable data and download one or two static images as “template” or “layout” and store it on the device as .GRF file(s). When you have downloaded the file and printed the first label, the second time you print anything it is only necessary to recall the stored image and print it together with the variable data. Furthermore, these data are not printed as one image, however, they are separated into those parts that contain data (it makes no sense to transmit blank lines or planes to the printer). All these parts are transmitted together with their co-ordinates so that they are reconstructed together – also together with the fixed part – on the printer.


              We use the host status – “~HS” – command to obtain the status; it also contains the number of stored images. I am wondering that, in the SDK, the PrinterStatus class is not containing this information.
              However, perhaps it is possible to use the FileUtil.retrieveFileNames method to verify which image files are yet stored in the device?


              I have yet seen that the (ZebraImage) GraphicsUtil.printImage (ZebraImageI, int, int, int, int, boolean) method
              is able to print the image when the last argument insideFormat is set to False. It would be interesting for me to set insideFormat to true – is it possible to send a couple of images in this way, to collect these images on
              the printer to a bigger image and to print it – or to store it on the device using storeImage?


              Some other questions:


              Are there still other parts of the SDK? For example, when I invoke the retrieveFileNames method above, a java.lang.NoClassDefFoundError occurs (Failed resolution of: Lcom/fasterxml/jackson/databind/ObjectMapper). (Currently I use a Samsung S5 with Android 5.0 for testing purposes, but in practice our customers use other devices with lower Android SDK versions.)


              (I have seen that the iMZ320 is yet among the Link-OS printers. Do you think that the Link-OS features have any advantages for our purpose?)


              Other question:


              Is it possible to log all data/bytes sent to the printer for debug purposes when the Zebra SDK is used?


              Thank you in advance.


              Regards, Hartmut Neubauer

              PANStreet International GmbH

            • Re: iMZ320/ZPL: How to use Z64 and LZ77 to compress data downloading to the printer
              Hartmut Neubauer



              I have now found that it is possible to use the DEFLATE algorithm. It is widely used by PKZIP, GZIP, ZLIB etc. and includes the LZ77 as well as Huffman encoding. Java and Android users can use the java.util.zip package and the Deflater class.

                • Re: iMZ320/ZPL: How to use Z64 and LZ77 to compress data downloading to the printer
                  Jim Jensen

                  The current version of ZebraDesigner (2.5.0) outputs graphics as ^GFA,b,c,d,:Z64:<data>:cccc. Does ZebraDesigner use the DEFLATE algorithm to produce the Z64 encoded data in the ZPL file?  The Zebra specs say LZ77 but DEFLATE is LZ77 with Huffman coding.


                  How are the ^GFA parameters b, c, d calculated when using Z64 encoded data?  Does the original image need to be a certain type (bmp, png, jpg, etc) and dithered prior to compressing with LZ77?


                  Is there a method in the Zebra SDK that actually produces Z64 encoded data?  I can only find one which produces B64 encoded data.