cod3monk / zpl Goto Github PK
View Code? Open in Web Editor NEWPython ZPL2 Library
License: GNU Affero General Public License v3.0
Python ZPL2 Library
License: GNU Affero General Public License v3.0
def draw_ellipse(self, width, height, thickness=1, color='B'):
assert color in 'BW', "invalid color"
self.code += "^GE,%i,%i,%i,%c" % (width, height, thickness, color)
def print_graphic(self, name, scale_x=1, scale_y=1):
self.code += "^XG,%s,%i,%i" % (name, scale_x, scale_y)
Can't write boxes just rectangles.
def draw_ellipse(self, width, height, thickness=1, color='B'):
assert color in 'BW', "invalid color"
self.code += "^GE%i,%i,%i,%c" % (width, height, thickness, color)
def print_graphic(self, name, scale_x=1, scale_y=1):
self.code += "^XG%s,%i,%i" % (name, scale_x, scale_y)
Isn't much correct without , ?
^GE80,80,1
instead of
^GE,80,80,1
@cod3monk Hey, we ran into another issue with the iso8859-1 encoding in the TCPPrinter class. We could not print any foreign language symbols. (ü,ä, à, °). We changed the encoding to utf-8 and it worked. Tested with zebra zd420.
The example code creates a png image that can not be printed,how can i generate a pdf file
Is there support for special characters? It doesn't look like it from my learning knowledge of python. I'm been messing around the last few hours with my printer try to make it work. The printer just spits out garbage for those characters. I have a method made to add "^FH" infront of the "^FD" commands and replacing special characters with hex codes according the ZPL2 dev guide. That hasn't seem to fixed it on my GK420t. I am using the Swiss 721 font that I loaded onto the printer.
Anyone have experience with Special Characters and how they handle them?
Most of my write_text lines look like this:
l.write_text(line, char_height=char_height, char_width=char_width, line_width=(label_width-2), justification='L', font='E:AH.FNT')
I'm trying to find out if it is my printer who is messing up or not.
Please publish a new version of the library.
I followed the advice to use the barcode() function. In my code using the barcode function makes no difference. The first the characters are cut off.
def create_zebra_qr_code_special(code_to_print) :
# label = zpl.Label(50,20,300)
# height = 15
# label.origin(10, height)
# label.write_barcode(height = 20, barcode_type= 'U', check_digit='Y')
# label.write_text(code_to_print)
# label.endorigin()
# code = label.preview()
# print(code)
l = Label(50,20,12) #12 -> 300dpi
#code_to_print = '000'+code_to_print #Die ersten 3 Zeichen werden verschluckt
code_to_print =code_to_print # Die ersten 3 Zeichen werden verschluckt
height =5 #Ausrichtung Oben,Unten -> Größere Zahl = weiter unten
l.origin(5, height,justification='2')
#Mögliche Label Typen, U,C,E,X,Q,2A,3
#Q= QR-Code, C = Barcode, E = anderer Barcode
#l.barcode('C', code_to_print, height=100,check_digit='Y') # height höhe des Barcodes in keine Ahnung welcher Einheit, Strichcode
l.barcode('Q',code_to_print,height=None, check_digit='Y', magnification='5') #height höhe des Barcodes in keine Ahnung welcher Einheit
l.write_text(code_to_print)
l.endorigin()
#l.preview() #Debugging, Anzeige des labels
return l.dumpZPL()
Following deprecation warning is shown:
DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead.
image = image.resize((int(width*self.dpmm), int(height*self.dpmm)), PIL.Image.NEAREST)
My settings:
MacOS,
python 3.11.0
zpl==0.1.10
pillow==9.3.0
Thank you for this library!
I see the printer.py file but at the lowest level it relies on:
def request_info(self, command):
raise Exception("not implemented in this printer class")
so it would seem this is not yet implemented?
I am trying to print QR codes on small labels to a USB connected printer from a Win10 Nuc (like) miniPC.
Any suggestions/guidance would be appreciated.
@cod3monk Hi, could you add the option to implement ^LRY on the beginning of the zpl code.
The ^LR command reverses the printing of all fields in the label format. It allows a field to appear as white over black or black over white. Thank you!
The code 12334AB988765
as an example, scans as 34AB988765
->
from PIL import Image
import zpl
def printlabel(title,code):
l = zpl.Label(25,38) #vertical, horizontal
l.origin(27,2) #horizontal, vertical
l.write_text("{}".format(title), char_height=3, char_width=1.5, line_width=25, justification='L',orientation='R')
l.endorigin()
qr_x = 9
qr_y = 2
l.origin(qr_x+3, qr_y) #horizontal, vertical
l.write_barcode(height=1, barcode_type='Q', errorCorrection='H',magnification=6)
l.write_text('{}'.format(code))
l.endorigin()
l.origin(qr_x,qr_y+1) #horizontal, vertical
l.write_text("{}".format(code), char_height=2, char_width=1.5, line_width=25, justification='L',orientation='R')
l.endorigin()
#Debugging
print(l.dumpZPL())
l.preview()
if __name__ == '__main__':
printlabel("Project: test",'12334AB988765')
@cod3monk could you add the option for an EAN13 Barcode. That would be ^BE.
Here is the reference in the zpl manual. Page 96
https://www.zebra.com/content/dam/zebra/manuals/printers/common/programming/zpl-zbi2-pm-en.pdf
Thank you!
Thanks for an amazing package, really helpful!
Just one issue. For UTF-8 characters (Cyrillic in my case), I use the font E:TT0003M_.FNT
. However, I can't pass it to the write_text()
function. It looks like there is a limit on single-char standard font names.
Would be awesome if you could lift that limit to enable use of other fonts.
Hello,
could you please add Barcode type "Q" for QR-Codes in the write_barcode Function?
Thank you!
I've bin trying to create QR Codes. By verifying that the code is correct I have found out, that the first characters of the text are missing.
This happens with the code from the example as well:
Calling this function:
def create_zebra_barcode() :
l = Label(100,80)
height = 0
l.origin(0,0)
l.write_text("Problem?", char_height=10, char_width=8, line_width=60, justification='C')
l.endorigin()
height += 20
l.origin(22, height)
l.write_barcode(height=None, barcode_type='Q', magnification=4)
l.write_text('https://github.com/cod3monk/zpl')
l.endorigin()
height += 20
l.origin(0, height)
l.write_text('Happy Troloween!', char_height=5, char_width=4, line_width=60,
justification='C')
l.endorigin()
print(l.dumpZPL())
l.preview()
Results in this zpl code:
^XA^FO0,0^A0N,120,96^FB720,1,0,C,0^FDProblem?&^FS^FO264,240^BQN,2,4,Q,7^FDhttps://github.com/cod3monk/zpl^FS^FO0,480^A0N,60,48^FB720,1,0,C,0^FDHappy Troloween!&^FS^XZ
If you are scanning the QR-Code the displayed text is: ps://github.com/cod3monk/zpl
Hello,
we cannot get the TCPPrinter class to work.
Could you please show us an example on how to initiliaze it.
We always get an error with args.utc in the initialization,
Whats should we input for args, if we should input anything?
printerTcp = zpl.TCPPrinter(host="127.0.0.1")
Thank you!
is there an option to set the width of the barcode
I hope that I don't misunderstand anything, but I was expecting functions like draw_ellipse() draw_box() to accept mm units, but the conversion is missing in these.
So I think this:
def draw_box(self, width, height, thickness=1, color='B', rounding=0): assert color in 'BW', "invalid color" assert rounding <= 8, "invalid rounding" self.code += "^GB%i,%i,%i,%c,%i" % (width, height, thickness, color, rounding)
should be like this:
def draw_box(self, width, height, thickness=1, color='B', rounding=0): assert color in 'BW', "invalid color" assert rounding <= 8, "invalid rounding" self.code += "^GB%i,%i,%i,%c,%i" % (width*self.dpmm, height*self.dpmm, thickness, color, rounding)
And maybe even the thickness should have a conversion in mm?
import zpl
l = zpl.Label(20,32)
l.origin(8,2)
l.barcode('Q', 'https://github.com/cod3monk/zpl/', magnification=7)
l.endorigin()
zp=zpl.TCPPrinter("<snip>")
zp.send_job(l)
zp.send_job(l)
causes exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<snip>\Python\3.11.0\Lib\site-packages\zpl\printer.py", line 244, in send_job
log.exception('exception')
^^^^^^^^^^^^^^^
TypeError: Logger.exception() missing 1 required positional argument: 'msg'
zp.send_job(l.dumpZPL())
works fine.
After the exception occurs you must re-instantiate zp
to use socket again.
Can you apply the possibility for Hex characters? (^FH...)
Thanks for the Python translater for ZPL. This is very helpful.
Do you have any insights on how to remotely send the converted ZPL to an actual Zebra printer endpoint using Python? Seems like it REALLY involved.
I'm aiming at a TLP 2824 Plus.
So far my research tells me:
Printer must be setup with the 10/100 Zebra Print Server
From here, I see a couple methods of remotely pushing ZPL to the printer, though neither seem direct:
Any leads on how I can simplify remote printing?
Thanks!
the \ line break in barcode_zpl assignment prevents the entire string from being formatted.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.