1

I'm trying to convert an image to ZPl and then print the label to a 6.5*4cm label on a TLP 2844 zebra printer on Python.

My main problems are: 1.Converting the image 2.Printing from python to the zebra queue (I've honestly tried all the obvious printing packages like zebra0.5/ win32 print/ ZPL...)

Any help would be appreciated.

EdHayes3
  • 1,777
  • 2
  • 16
  • 31

3 Answers3

1

I had the same issue some weeks ago. I made a python script specifically for this printer, with some fields available. I commented (#) what does not involve your need, but left it in as you may find it helpful.

I also recommend that you set your printer to the EPL2 driver, and 5cm/s print speed. With this script you'll get the PNG previews with an EAN13 formatted barcode. (If you need other formats, you might need to hit the ZPL module docs.)

Please bear in mind that if you print with ZLP 2844, you will either need to use their paid software, or you will need to manually configure the whole printer.

import os
import zpl
#import pandas

#df= pandas.read_excel("Datos.xlsx")
#a=pandas.Series(df.GTIN.values,index=df.FINAL).to_dict()

for elem in a:

    l = zpl.Label(15,25.5)
    height = 0
    l.origin(3,1)
    l.write_text("CUIT: 30-11111111-7", char_height=2, char_width=2,   line_width=40)
    l.endorigin()

    l.origin(2,5)
    l.write_text("Art:", char_height=2, char_width=2, line_width=40)
    l.endorigin()

    l.origin(5.5,4)
    l.write_text(elem, char_height=3, char_width=2.5, line_width=40)
    l.endorigin()

    l.origin(2, 7)
    l.write_barcode(height=40, barcode_type='2', check_digit='N')
    l.write_text(a[elem])
    l.endorigin()

    height += 8
    l.origin(8.5, 13)
    l.write_text('WILL S.A.', char_height=2, char_width=2, line_width=40)
    l.endorigin()

    print(l.dumpZPL())
    lista.append(l.dumpZPL())

    l.preview()

To print the previews without having to watch and confirm each preview, I ended up modifying the ZPL preview method, to return an IO variable so I can save it to a file.

fake_file = io.BytesIO(l.preview())
img = Image.open(fake_file)
img = img.save('tags/'+'name'+'.png')

On the Label.py from ZPL module (preview method):

#Image.open(io.BytesIO(res)).show().  <---- comment out the show, but add the return of the BytesIO
return res
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Jay Lopez
  • 71
  • 1
  • 9
  • Thanks for the code. I'm not seeing where you have an actual .png on the label. Looks like its all text? – SeaDude Dec 29 '20 at 09:03
0

I had similar issues and created a .net core application which takes an image and converts it to ZPL, either to a file or to the console so it's pipeable in bash scripts. You could package it with your python app call it as a subprocess like so:

output = subprocess.Popen(["zplify", "path/to/file.png"], stdout=subprocess.PIPE).communicate()[0]

Or feel free to use my code as a reference point and implement it in python.

Once you have a zpl file or stream you can send it directly to a printer using lpr if you're on linux. If on windows you can connect to a printer using it's IP address as shown in this stack overflow question

nelsontruran
  • 514
  • 4
  • 18
0

For what is worth and for anyone else reference, was facing a similar situation and came up with a solution. To whom it may help:

  1. Converting the image? After trying many libraries i came across ZPLGRF although it seems the demo is focused on PDF only, i found in the source that there is a from_image() class property that could convert from image to zpl combining it part of the demo/exaples. Full code description below

  2. Printing from python to the zebra queue? Many libraries again but i settled with ZEBRA seem to be the most straight forward one to send raw zpl to a zebra printer

CODE

from zplgrf import GRF    
from zebra import Zebra

#Open the image file and generate ZPL from it
with open(path_to_your_image, 'rb') as img:
    grf = GRF.from_image(img.read(), 'LABEL')
    grf.optimise_barcodes()
    zpl_code = grf.to_zpl

#Setup and print to Zebra Printer
z = Zebra()

#This will return a list of all the printers on a given machine as a list
#['printer1', 'printer2', ...]
z.getqueues()

#If or once u know the printer queue name then u can set it up with
z.setqueue('printer1')

#And now is ready to send the raw ZPL text
z.output(zpl_code )

The above i have tested successfully with a Zebra GX430t printer connected via USB in a Windows 11 machine.

Hope it helps

Alejandro Suarez
  • 149
  • 3
  • 16