IntOverflow
IntOverflow

Reputation: 93

ZPL: Binary B64 and compressed Z64 encoding

Maybe someone can help me with my Zebra ZPL problem. The ZPL manual doesn't really help me. I want to transfer binary (with ZPL B64) and compressed binary (with ZPL Z64) image data to the printer.

I was able to find the following information:

Has any of you done that yet?

Thank you very much.

Upvotes: 6

Views: 6529

Answers (2)

Franck Theeten
Franck Theeten

Reputation: 140

These two pages contain interesting code in Java to write a converter encoding an image file to Z64 :

http://www.jcgonzalez.com/img-to-zpl-online

https://gist.github.com/trevarj/1255e5cbc08fb3f79c3f255e25989a18

I wrote a Python port of the Java class of the first link, taking the form of a Python3 class : https://github.com/ftheeten/python_zebra_adapter/blob/main/class_zebra.py

You can use afterwards the Python Pillow library to generate the images to be converted. This approach is very flexible as you can use any font having a TTF file.

E.G.

import socket
from PIL import ImageFont, ImageDraw, Image
import numpy as np
...

img=FUNCTION_GENERATING_A_PILLOW
zpl=Class_zpl()
zpl.set_compress(False)
zpl.set_blacklight_percentage(60)
str_label=zpl.process(img)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((PRINTER_IP, PORT_PRINTER))
s.sendall(str.encode(str_label))
#data = s.recv(1024)
s.close()

Upvotes: 0

GSerg
GSerg

Reputation: 78134

The ZPL manual doesn't really help me.

Tell me about it!

  • The "LZ77" algorithm mentioned in the manual is in fact the ZLIB format. I used http://zlib.net for that.
  • The "CRC" mentioned in the manual is in fact CRC16-CCITT. Code I used: http://sanity-free.com/133/crc_16_ccitt_in_csharp.html.

    In order to properly calculate it:

    • Compress the picture bits using ZLIB (the picture must be PixelFormat.Format1bppIndexed, and the picture bits are best accessed with Bitmap.LockBits).
    • Encode the compressed data into Base64. No whitespace or line breaks allowed.
    • Convert the Base64 string to a byte array according to ASCII encoding (System.Text.Encoding.ASCII.GetBytes(base64string)).
    • Calculate the CRC over that byte array. The Initial CRC Value must be zero.

Upvotes: 7

Related Questions