1
votes

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.

2
Add your code which you have trieHitesh Kansagara
Did you ever get anywhere with this? I have the same issue. Would be so awesome to have a .png-to-EPL/ZPL converter.SeaDude

2 Answers

1
votes

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
0
votes

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