Reputation: 93
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
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
Reputation: 78134
The ZPL manual doesn't really help me.
Tell me about it!
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:
PixelFormat.Format1bppIndexed
, and the picture bits are best accessed with Bitmap.LockBits
).System.Text.Encoding.ASCII.GetBytes(base64string)
).Upvotes: 7