Zpl to png converter
Get via App Store Read this post in our app!
Printing PNG images to a zebra network printer
I am trying to find a way of printing images to a zebra and having a lot of trouble.
According to the docs:
The first encoding, known as B64, encodes the data using the MIME Base64 scheme. Base64 is used to encode e-mail atachedments .
Base64 encodes six bits to the byte, for an expantion of 33 percent over the un-enclosed data.
The second encoding, known as Z64, first compresses the data using the LZ77 algorithm to reduce its size. (This algorithm is used by the PKZIP and is intergral to the PNG graphics format.)
The compressed data is then encoded using the MIME Base64 scheme as described above.
A CRC will be calculated accross the Base64-encoded data.
But it doesn't have a great deal more info.
Basically I was trying encoding with
Then trying to print with something like:
From the sounds of it, either B64 or Z64 are both accepted.
I've tried a few variations, and a couple of methods for generating the CRC and calculating the 'size'. But none seem to work and the download of the graphics to the printer is always getting aborted.
Has anyone managed to accomplish something like this? Or knows where I am going wrong?
All credit for me coming to this answer was from LabView Forum user Raydur. He posts a LabView solution that can be opened up in LabView to send images down. I personally didn't run it with my printer, I just used it to figure out the correct image code so I could replicate it in my code. The big thing that I was missing was padding my Hexadecimal code. For example: 1A is fine, but if you have just A, you need to pad a 0 in front of it to send 0A. The size of the file in the ZPL you are sending is also the original size of the byte array, not the final string representation of the data.
DG command and GRF format (page 124) to download images. Volume Two adds details on an optional compression format (page 52).
First, you have to convert the image to a 1bpp bi-level image, then convert it to a hex-encoded string. You can further compress the image to reduce transmission time. You can then print the image with the ^ID command.
While there is inherent support for PNG images in the
DY command, it is poorly documented and does not seem to work on certain models of printers. The ZB64 format is basically not documented, and attempts to get more information from Zebra support have been fruitless. If you have your heart set on ZB64, you can use the Java based Zebralink SDK (look to ImagePrintDemo.java and com.zebra.sdk.printer.internal.GraphicsConversionUtilZpl.sendImageToStream ).
Once you have the command data, it can be sent via TCP/IP if the printer has a print-server, or it can be sent by writing in RAW format to the printer.
The code below prints a 5 kB PNG as a 13 kB compressed GRF (60 kB uncompressed):
For some reason I cannot get B64 to work, but luckily I was able to Google my way into making Z64 work (in 3 soul-searching days or so) using plain old JavaScript.
Somewhere else on the ZPL programming Guide you stumble upon the The CISDFCRC16 command--let's be cryptic, why not--section, which states:
"The value of the field is calculated the CRC-16 for the contents of a specified file using the CRC16-CCITT polynomial which is x^16 + x^12 + x^5 + 1. It is calculated using an initial CRC of 0x0000."
Japanglish aside, you can now check out the Catalogue of parametrised CRC algorithms with 16 bits (http://reveng.sourceforge.net/crc-catalogue/16.htm) and look for the XMODEM algorithm, which happens to be
Aha. I then started looking for the rest of the code I needed and stumbled upon the following:
- LZ77-Algorithm-Based JavaScript Compressor (http://lab.polygonpla.net/js/tinylz77.html)
- base-64.js (https://github.com/beatgammit/base64-js/blob/master/lib/b64.js)
- Lammert Bies' 2008 CRC Library (http://www.lammertbies.nl/comm/info/crc-calculation.html) ported from ANSI C--with the precaution to bitwise-AND with 0xffff the update function return value since JavaScript treats every number as a 32-bit signed integer.
So I read the file as a byte array (Uint8Array), parse it as a string, compress it with LZ77, turn that back into a byte array and encode it using base64, at which point I calculate the CRC and paste it all into my ZPL
DT command for savings of about 40%. Beautiful.
Unfortunately I'm developing a proprietary solution so I cannot post any code.
-What one man did another can do.
After looking at the ZPL manual you need to calculate the Cyclic Redundancy Check (CRC) for the image. Here is some C Code that calculates the CRC (source):
You can also refer to Wikipedia's page on CRC, as it contains other code examples as well.
Everything else you are sending down looks good. I would look into using one of the Zebra SDKs. I know the Android one will send an image to the printer and save it for you.