class Zebra_Label
Used to build a ZPL2 label and send a print commandline to a specified printer on a specified server. Notes ----- all dimensions are given in millimeters and automatically converted to printer dot units. Parameters ---------- height : int height of the label in mm. width : int width of the label in mm. dpmm : int dots per millimeter, 8.0 for 203 dpi, 12 for 300 dpi. server : str The server on which to print. queue : str The printer to print on. Attributes ---------- height : int height of the label in mm. width : int width of the label in mm. dpmm : int dots per millimeter, 8.0 for 203 dpi, 12 for 300 dpi. server : str The server on which to print. queue : str The printer to print on. code : str ZPL code string, each function adds to this and this is what is eventually send to the printer. graph : py2neo.Graph The connection to the database
/tf/active/vicechatdev/resources/printers.py
54 - 636
moderate
Purpose
Used to build a ZPL2 label and send a print commandline to a specified printer on a specified server. Notes ----- all dimensions are given in millimeters and automatically converted to printer dot units. Parameters ---------- height : int height of the label in mm. width : int width of the label in mm. dpmm : int dots per millimeter, 8.0 for 203 dpi, 12 for 300 dpi. server : str The server on which to print. queue : str The printer to print on. Attributes ---------- height : int height of the label in mm. width : int width of the label in mm. dpmm : int dots per millimeter, 8.0 for 203 dpi, 12 for 300 dpi. server : str The server on which to print. queue : str The printer to print on. code : str ZPL code string, each function adds to this and this is what is eventually send to the printer. graph : py2neo.Graph The connection to the database
Source Code
class Zebra_Label:
"""
Used to build a ZPL2 label and send a print commandline to a specified
printer on a specified server.
Notes
-----
all dimensions are given in millimeters and automatically converted to
printer dot units.
Parameters
----------
height : int
height of the label in mm.
width : int
width of the label in mm.
dpmm : int
dots per millimeter, 8.0 for 203 dpi, 12 for 300 dpi.
server : str
The server on which to print.
queue : str
The printer to print on.
Attributes
----------
height : int
height of the label in mm.
width : int
width of the label in mm.
dpmm : int
dots per millimeter, 8.0 for 203 dpi, 12 for 300 dpi.
server : str
The server on which to print.
queue : str
The printer to print on.
code : str
ZPL code string, each function adds to this and this is what is eventually send to the printer.
graph : py2neo.Graph
The connection to the database
"""
def __init__(self, height, width=110.0, dpmm=8.0,server="10.200.200.12",queue="zebra_labels_lier", labeltype="Regular"):
"""
Creates one (or more) ZPL2 labels.
*height* and *width* are given in millimetersabe
*dpmm* refers to dots per millimeter (e.g. 12 for 300dpi)
8 should do for 200dpi
"""
self.height = height
self.width = width
self.dpmm = dpmm
self.labeltype=labeltype
self.code = "^XA"
self.graph = Graph(config.DB_ADDR, auth=config.DB_AUTH, name=config.DB_NAME)
self.server=server
self.queue=queue
self.setup_queue()
return
def setup_queue(self):
"""
Checks if a directory for the cups software exists, if not creates it and creates a new client.conf file for the server
"""
if not os.path.exists('/etc/cups'):
os.mkdir('/etc/cups')
# This is the VPN IP address of the local print server
try:
os.remove("/etc/cups/client.conf")
except:
pass
os.system("echo 'ServerName "+self.server+"' > /etc/cups/client.conf")
return
def print_lis_label(self,lis_obj_uid):
"""
Function containing the various printer designs. A predefined function for each sets up the print code, and a switcher functions
selects the correct function
Parameters
----------
lis_obj_uid : str
The UID of the object we wish to print
Returns
-------
I'm actually not sure whether this would return the function, or the product of the function..
I'd assume the product, in which case it doesn't return anything.
"""
def print_organ_eppendorf(print_obj):
objectname = self.graph.run(f"MATCH (o:Organ {{UID:'{print_obj['UID']}'}})<--(e:ExpItem) RETURN DISTINCT e.N").to_ndarray()[0][0]
self.set_darkness(25)
self.origin(42, 3.875)
self.write_barcode(height=3, barcode_type='X')
self.write_text(print_obj['UID'])
self.endorigin()
self.origin(50, 3.25)
self.write_text(objectname, char_height=2.5, char_width=2.5)
self.endorigin()
self.origin(50, 5.75)
self.write_text(dt.datetime.now().strftime('%Y-%m-%d'), char_height=2.5, char_width=2.5)
self.endorigin()
self.origin(50,8.25)
self.write_text(print_obj['N'], char_height=2.5, char_width=2.5)
self.endorigin()
self._print()
return
def print_organ(print_obj):
customer=self.graph.run("MATCH (o:Organ {UID:'"+print_obj['UID']+"'})<-[*]-(c:Customer) RETURN DISTINCT c.N").evaluate()
sample = self.graph.run(f"MATCH (o:Organ {{UID:'{print_obj['UID']}'}})<--(e:ExpItem) RETURN DISTINCT e.N").evaluate()
organ = self.graph.run(f"""MATCH (o:Organ {{UID:'{print_obj['UID']}'}})
RETURN CASE
WHEN o.Alias IS NOT NULL THEN o.N + ' - (' + o.Alias + ')'
ELSE o.N
END AS organ""").evaluate()
external_id = print_obj['external_N']
self.set_darkness(30)
self.origin(23.75, 8.25)
self.write_barcode(height=6, barcode_type='X')
self.write_text(print_obj['UID'])
self.endorigin()
img=Image.open("./images/Logoringsblack.png")
self.origin(23.75, 27)
self.write_graphic(img.convert('1'), 15)
self.endorigin()
self.origin(45, 9.5)
self.write_text(customer, char_height=4, char_width=4, justification='L')
self.endorigin()
self.origin(45, 17)
self.write_text(sample, char_height=4, char_width=4, justification='L')
self.endorigin()
self.origin(45, 24.5)
self.write_text(organ, char_height=4, char_width=3, justification='L')
self.endorigin()
self.origin(45, 32)
self.write_text(external_id, char_height=4, char_width=4, justification='L')
self.endorigin()
self.origin(45, 39.5)
self.write_text('Date:' + dt.datetime.now().strftime('%Y-%m-%d'), char_height=4, char_width=4, justification='L')
self.endorigin()
self._print()
return
def print_study(print_obj):
customer=self.graph.run("MATCH (s:Study {UID:'"+print_obj['UID']+"'})<--(c:Customer) RETURN c.N").evaluate()
if customer==None:
customer = "internal"
study_name=print_obj['N']
study_cust_ref=print_obj.get('external_N','void')
self.origin(23.75, 8.25)
self.write_barcode(height=6, barcode_type='X')
self.write_text(print_obj['UID'])
self.endorigin()
img=Image.open("./images/Logoringsblack.png")
self.origin(23.75, 27)
self.write_graphic(img.convert('1'),15)
self.endorigin()
self.origin(45, 9.5)
self.write_text("Customer: "+customer, char_height=5, char_width=4, justification='L')
self.endorigin()
self.origin(45, 19.5)
self.write_text("Study: "+study_name, char_height=5, char_width=4, justification='L')
self.endorigin()
self.origin(45, 29.5)
self.write_text("Ext ref: "+study_cust_ref, char_height=5, char_width=4, justification='L')
self.endorigin()
self._print()
return
def print_parblock_eppendorf(print_obj):
organ = self.graph.run(f"MATCH (:Parblock {{UID:'{print_obj['UID']}'}})<--(o:Organ) RETURN o LIMIT 1").to_subgraph()
self.set_darkness(15)
self.origin(42, 3.875)
self.write_barcode(height=3, barcode_type='X')
self.write_text(print_obj['N'])
self.endorigin()
self.origin(50, 3.25)
self.write_text(print_obj['N'], char_height=2.5, char_width=2.5)
self.endorigin()
self.origin(50, 5.75)
self.write_text(dt.datetime.now().strftime('%Y-%m-%d'), char_height=2.5, char_width=2.5)
self.endorigin()
self.origin(50,8.75)
if print_obj.get('external_N',False):
self.write_text(print_obj['external_N'], char_height=2.5, char_width=2.5)
elif organ.get('external_N', False):
self.write_text(organ['external_N'], char_height=2.5, char_width=2.5)
self.endorigin()
self._print()
def print_parblock(print_obj):
organ = self.graph.run(f"MATCH (:Parblock {{UID:'{print_obj['UID']}'}})<--(o:Organ) RETURN o LIMIT 1").to_subgraph()
self.origin(20, 2)
self.write_barcode(height=7, barcode_type='X')
self.write_text(print_obj['N'])
self.endorigin()
self.origin(40,2)
self.write_text(print_obj['N'], char_height=3, char_width=3, justification='L')
self.endorigin()
self.origin(40, 7)
self.write_text(organ['N'], char_height=3, char_width=3, justification='L')
self.endorigin()
if organ.get('external_N',False):
self.origin(40, 12)
self.write_text(organ['external_N'], char_height=3, char_width=3, justification='L')
self.endorigin()
self._print()
return
def print_slide(print_obj):
customer = self.graph.run(f"""MATCH (:Slide {{UID:'{print_obj['UID']}'}})<-[*]-(c:Customer)
RETURN DISTINCT CASE WHEN c.shorthand IS NOT NULL THEN c.shorthand ELSE c.N END""").evaluate()
study = self.graph.run(f"MATCH (:Slide {{UID:'{print_obj['UID']}'}})<-[*]-(s:Study) RETURN DISTINCT s").to_subgraph()
self.set_darkness(15)
self.field_orientation('B')
self.origin(61.25, 28.75)
self.write_barcode(height=5, barcode_type='X', orientation='B')
self.write_text(print_obj['N'])
self.endorigin()
self.origin(57.5, 6.25)
self.write_text(print_obj['N'],char_height=3.75, char_width=3.75, orientation='B')
self.endorigin()
self.origin(57.625, 6.25)
self.write_text(print_obj['N'],char_height=3.75, char_width=3.75, orientation='B')
self.endorigin()
self.origin(61.25, 6.25)
self.write_text(dt.datetime.now().strftime('%Y-%m-%d'), char_height=3.125, char_width=3.125, orientation='B')
self.endorigin()
self.origin(61.375, 6.25)
self.write_text(dt.datetime.now().strftime('%Y-%m-%d'), char_height=3.125, char_width=3.125, orientation='B')
self.endorigin()
self.origin(65, 6.25)
self.write_text(print_obj['T'], char_height=3.125, char_width=3.125, orientation='B')
self.endorigin()
self.origin(65.125, 6.25)
self.write_text(print_obj['T'], char_height=3.125, char_width=3.125, orientation='B')
self.endorigin()
self.origin(68.75, 6.25)
self.write_text(customer, char_height=3.125, char_width=3.125, orientation='B')
self.endorigin()
self.origin(68.875, 6.25)
self.write_text(customer, char_height=3.125, char_width=3.125, orientation='B')
self.endorigin()
self.origin(72.5, 6.25)
self.write_text(study['external_N'], char_height=3.125, char_width=3.125, orientation='B')
self.endorigin()
self.origin(72.725, 6.25)
self.write_text(study['external_N'], char_height=3.125, char_width=3.125, orientation='B')
self.endorigin()
self._print()
return
def print_other(print_obj):
name=print_obj['N']
obj_type=list(print_obj._labels)[0]
today = dt.datetime.now().strftime('%Y-%m-%d')
self.origin(2, 2)
self.write_barcode(height=7, barcode_type='X')
self.write_text(print_obj['UID'])
self.endorigin()
img=Image.open("./images/Logoringsblack.png")
self.origin(2, 25)
self.write_graphic(img.convert('1'),15)
self.endorigin()
self.origin(25,2)
self.write_text("Object: "+obj_type, char_height=5, char_width=4, justification='L')
self.endorigin()
self.origin(25,11)
self.write_text("Name: "+name, char_height=5, char_width=4, justification='L')
self.endorigin()
self.origin(25,20)
self.write_text("Date: "+today, char_height=5, char_width=4, justification='L')
self.endorigin()
self._print()
return
g_text="match (o {UID:'"+lis_obj_uid+"'}) return o"
print_objs=self.graph.run(g_text).to_subgraph()
if print_objs != None:
print_obj=list(print_objs.nodes)[0]
obj_type=list(print_obj._labels)[0]
if self.labeltype=='Eppendorf':
switcher = {
'Organ':print_organ_eppendorf,
'Parblock':print_parblock_eppendorf,
}
else:
switcher = {
'Organ':print_organ,
'Study':print_study,
'Parblock':print_parblock,
'Slide':print_slide
}
func = switcher.get(obj_type, print_other)
return func(print_obj)
def labelhome(self, x, y, justification=None):
"""
set label home at x and y (in millimeters)
justification is 0 for left, 1 for right, and 2 for auto
"""
self.code += "^LH%i,%i" % (x*self.dpmm, y*self.dpmm)
if justification != None:
assert justification in '012', "invalid justification"
self.code += ',' + justification
def origin(self, x, y, justification=None):
"""
new block located at x and y (in millimeters)
justification is 0 for left, 1 for right, and 2 for auto
"""
self.code += "^FO%i,%i" % (x*self.dpmm, y*self.dpmm)
if justification != None:
assert justification in '012', "invalid justification"
self.code += ',' + justification
def endorigin(self):
self.code += '^FS'
def set_darkness(self, value):
"""
sets the darkness of the printed label. The value input is integer between 0 - 30,
which corresponds to (no darkness 0) or (full darkness 30)
"""
assert (isinstance(value, int)), "The value must be an integer"
assert (value >= 0 and value <= 30), "The value must be between 0 and 30"
self.code += "~SD" + str(value)
def textblock(self, width, justification='C', lines=1):
"""
new text block
width of textblock in millimeters
"""
assert justification in ['L','R','C','J']
self.code += "^FB%i,%i,%i,%s,%i" % (width*self.dpmm, lines, 0, justification, 0)
def write_text(self, text, char_height=None, char_width=None, font='0', orientation='N',
line_width=None, max_line=1, line_spaces=0, justification='L', hanging_indent=0):
if char_height and char_width and font and orientation:
assert orientation in 'NRIB', "invalid orientation"
if re.match(r'^[A-Z0-9]$', font):
self.code += "^A%c%c,%i,%i" % (font, orientation, char_height*self.dpmm,
char_width*self.dpmm)
elif re.match(r'[REBA]?:[A-Z0-9\_]+\.(FNT|TTF|TTE)', font):
self.code += "^A@%c,%i,%i,%s" % (orientation, char_height*self.dpmm,
char_width*self.dpmm, font)
else:
raise ValueError("Invalid font.")
if line_width:
assert justification in "LCRJ", "invalid justification"
self.code += "^FB%i,%i,%i,%c,%i" % (line_width*self.dpmm, max_line, line_spaces,
justification, hanging_indent)
self.code += "^FD%s" % text
if justification == 'C':
self.code += "\&"
def set_default_font(self, height, width, font='0'):
"""
sets default font from here onward
height and width are given in milimeters
"""
assert re.match(r'[A-Z0-9]', font), "invalid font"
self.code += "^CF%c,%i,%i" % (font, height*self.dpmm, width*self.dpmm)
def change_international_font(self, character_set=28, remaps=[]):
"""
change the international font/encoding, that enables you to call
up the international character set you want to use for printing
"remaps" arg is a list of tuples with the number of the source
character and the substitute character destination.
"""
ci_code = '^CI%i' % (character_set)
charset_regex_range = "(3[0-6]|[12]?[0-9])"
range_regex = "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])"
ci_regex = r"^\^CI%s((\,%s,%s){1,})*$" % (
charset_regex_range, range_regex, range_regex)
for src, dest in remaps:
ci_code += ',%i,%i' % (src, dest)
assert re.match(ci_regex, ci_code), "invalid character set"
self.code += ci_code
def _convert_image(self, image, width, height, compression_type='A'):
'''
converts *image* (of type PIL.Image) to a ZPL2 format
compression_type can be one of ['A', 'B', 'C']
returns data
'''
image = image.resize((int(width*self.dpmm), int(height*self.dpmm)))
# invert, otherwise we get reversed B/W
# https://stackoverflow.com/a/38378828
image = ImageOps.invert(image.convert('L')).convert('1')
if compression_type == "A":
# return image.tobytes().encode('hex').upper()
return image.tobytes().hex().upper()
# TODO this is not working
#elif compression_type == "B":
# return image.tostring()
else:
raise Exception("unsupported compression type")
def upload_graphic(self, name, image, width, height=0):
"""in millimeter"""
if not height:
height = int(float(image.size[1])/image.size[0]*width)
assert 1 <= len(name) <= 8, "filename must have length [1:8]"
totalbytes = math.ceil(width*self.dpmm/8.0)*height*self.dpmm
bytesperrow = math.ceil(width*self.dpmm/8.0)
data = self._convert_image(image, width, height)
self.code += "~DG%s.GRF,%i,%i,%s" % (name, totalbytes, bytesperrow, data)
return height
def write_graphic(self, image, width, height=0, compression_type="A"):
"""
embeddes image with given width
image has to be of type PIL.Image
if height is not given, it will be chosen proportionally
"""
if not height:
height = int(float(image.size[1])/image.size[0]*width)
totalbytes = math.ceil(width*self.dpmm/8.0)*height*self.dpmm
bytesperrow = math.ceil(width*self.dpmm/8.0)
data = self._convert_image(image, width, height, compression_type=compression_type)
if compression_type == "A":
self.code += "^GFA,%i,%i,%i,%s" % (len(data), totalbytes, bytesperrow, data)
# TODO this is not working:
elif compression_type == "B":
self.code += "^GFB,%i,%i,%i,%s" % (len(data), totalbytes, bytesperrow, data)
else:
raise Exception("Unsupported compression type.")
return height
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)
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)
def reverse_print(self, active='Y'):
assert active in ['Y', 'N'], "invalid parameter"
self.code += "^LR%s" % active
def run_script(self, filename):
self.code += "^XF%s^FS"
def write_field_number(self, number, name=None, char_height=None, char_width=None, font='0',
orientation='N', line_width=None, max_line=1, line_spaces=0,
justification='L', hanging_indent=0):
if char_height and char_width and font and orientation:
assert re.match(r'[A-Z0-9]', font), "invalid font"
assert orientation in 'NRIB', "invalid orientation"
self.code += "^A%c%c,%i,%i" % (font, orientation, char_height*self.dpmm,
char_width*self.dpmm)
if line_width:
assert justification in "LCRJ", "invalid justification"
self.code += "^FB%i,%i,%i,%c,%i" % (line_width*self.dpmm, max_line, line_spaces,
justification, hanging_indent)
self.code += "^FN%i" % number
if name:
assert re.match("^[a-zA-Z0-9 ]+$", name), "name may only contain alphanumerical " + \
"characters and spaces"
self.code += '"%s"' % name
def barcode_field_default(self, module_width, bar_width_ratio, height):
self.code += '^BY%s,%s,%s' % (module_width * self.dpmm,
bar_width_ratio,
height * self.dpmm)
def field_orientation(self, orientation, justification=None):
"""
sets default field orientation, and optionally, justification
justification is 0 for left, 1 for right, and 2 for auto
"""
assert orientation in 'NRIB', "invalid orientation"
self.code += '^FW%s' % orientation
if justification != None:
assert justification in '012', "invalid justification"
self.code += ',' + justification
def write_barcode(self, height, barcode_type, orientation='N', check_digit='N',
print_interpretation_line='Y', print_interpretation_line_above='N',
magnification=1, errorCorrection='Q', mask='7', mode='N'):
# TODO split into multiple functions?
# TODO support all ^B barcode types
# guard for only currently allowed bar codes
assert barcode_type in '23AQUCEX', "invalid barcode type"
if barcode_type in '2A':
barcode_zpl = '^B%s%s,%i,%s,%s,%s' % (barcode_type, orientation, height,
print_interpretation_line,
print_interpretation_line_above,
check_digit)
elif barcode_type == '3':
barcode_zpl = '^B%s%s,%s,%i,%s,%s' % (barcode_type, orientation,
check_digit, height,
print_interpretation_line,
print_interpretation_line_above)
elif barcode_type == 'Q':
assert orientation == 'N', 'QR Code orientation may only be N'
model = 2 # enchanced model, always recommended according to ZPL II documentation
assert magnification in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], \
'QR Code maginification may be 1 - 10.'
assert errorCorrection in 'HQML', 'QR Code errorCorrection may be H (more reliable, ' \
'less dense), Q, M or L (less reliable, more dense).'
assert mask in [1, 2, 3, 4, 5, 6, 7, '1', '2', '3', '4', '5', '6', '7'], \
'QR Code mask may be 1 - 7.'
barcode_zpl = '^B%s%s,%s,%s,%s,%s' % (barcode_type, orientation,
model, magnification, errorCorrection, mask)
elif barcode_type == 'X':
barcode_zpl = '^B%s%s,%s,%s,%s,%s,%s,%s,%s' % (barcode_type,orientation,height,"200","0","0","6","~","1")
elif barcode_type == 'U':
barcode_zpl = '^B%s%s,%s,%s,%s,%s' % (barcode_type, orientation, height,
print_interpretation_line,
print_interpretation_line_above,
check_digit)
elif barcode_type == 'C':
barcode_zpl = '^B%s%s,%i,%s,%s,%s,%s' % (barcode_type, orientation, height,
print_interpretation_line,
print_interpretation_line_above,
check_digit, mode)
elif barcode_type == 'E':
barcode_zpl = '^B%s%s,%i,%s,%s' % (barcode_type, orientation, height,
print_interpretation_line,
print_interpretation_line_above)
self.code += barcode_zpl
def dumpZPL(self):
return self.code+"^XZ"
def saveFormat(self, name):
self.code= self.code[:3] + ("^DF%s^FS" % name) + self.code[3:]
def _print(self):
if not os.path.exists(os.path.join(os.path.abspath('.'),'temp')):
os.mkdir(os.path.join(os.path.abspath('.'),'temp'))
temp_file=os.path.join(os.path.abspath('.'),'temp','label_out.zpl')
with open(temp_file, 'w') as f:
f.write(self.dumpZPL())
if config.PRINT_ZPL:
os.system('lp -d '+self.queue+' -o raw '+temp_file)
print('lp -d '+self.queue+' -o raw '+self.code+ "^XZ")
else:
print('lp -d '+self.queue+' -o raw '+self.code+ "^XZ")
os.remove(temp_file)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
- | - |
Parameter Details
bases: Parameter of type
Return Value
Returns unspecified type
Class Interface
Methods
__init__(self, height, width, dpmm, server, queue, labeltype)
Purpose: Creates one (or more) ZPL2 labels. *height* and *width* are given in millimetersabe *dpmm* refers to dots per millimeter (e.g. 12 for 300dpi) 8 should do for 200dpi
Parameters:
height: Parameterwidth: Parameterdpmm: Parameterserver: Parameterqueue: Parameterlabeltype: Parameter
Returns: None
setup_queue(self)
Purpose: Checks if a directory for the cups software exists, if not creates it and creates a new client.conf file for the server
Returns: None
print_lis_label(self, lis_obj_uid)
Purpose: Function containing the various printer designs. A predefined function for each sets up the print code, and a switcher functions selects the correct function Parameters ---------- lis_obj_uid : str The UID of the object we wish to print Returns ------- I'm actually not sure whether this would return the function, or the product of the function.. I'd assume the product, in which case it doesn't return anything.
Parameters:
lis_obj_uid: Parameter
Returns: See docstring for return details
labelhome(self, x, y, justification)
Purpose: set label home at x and y (in millimeters) justification is 0 for left, 1 for right, and 2 for auto
Parameters:
x: Parametery: Parameterjustification: Parameter
Returns: None
origin(self, x, y, justification)
Purpose: new block located at x and y (in millimeters) justification is 0 for left, 1 for right, and 2 for auto
Parameters:
x: Parametery: Parameterjustification: Parameter
Returns: None
endorigin(self)
Purpose: Performs endorigin
Returns: None
set_darkness(self, value)
Purpose: sets the darkness of the printed label. The value input is integer between 0 - 30, which corresponds to (no darkness 0) or (full darkness 30)
Parameters:
value: Parameter
Returns: None
textblock(self, width, justification, lines)
Purpose: new text block width of textblock in millimeters
Parameters:
width: Parameterjustification: Parameterlines: Parameter
Returns: None
write_text(self, text, char_height, char_width, font, orientation, line_width, max_line, line_spaces, justification, hanging_indent)
Purpose: Performs write text
Parameters:
text: Parameterchar_height: Parameterchar_width: Parameterfont: Parameterorientation: Parameterline_width: Parametermax_line: Parameterline_spaces: Parameterjustification: Parameterhanging_indent: Parameter
Returns: None
set_default_font(self, height, width, font)
Purpose: sets default font from here onward height and width are given in milimeters
Parameters:
height: Parameterwidth: Parameterfont: Parameter
Returns: None
change_international_font(self, character_set, remaps)
Purpose: change the international font/encoding, that enables you to call up the international character set you want to use for printing "remaps" arg is a list of tuples with the number of the source character and the substitute character destination.
Parameters:
character_set: Parameterremaps: Parameter
Returns: None
_convert_image(self, image, width, height, compression_type)
Purpose: converts *image* (of type PIL.Image) to a ZPL2 format compression_type can be one of ['A', 'B', 'C'] returns data
Parameters:
image: Parameterwidth: Parameterheight: Parametercompression_type: Parameter
Returns: See docstring for return details
upload_graphic(self, name, image, width, height)
Purpose: in millimeter
Parameters:
name: Parameterimage: Parameterwidth: Parameterheight: Parameter
Returns: None
write_graphic(self, image, width, height, compression_type)
Purpose: embeddes image with given width image has to be of type PIL.Image if height is not given, it will be chosen proportionally
Parameters:
image: Parameterwidth: Parameterheight: Parametercompression_type: Parameter
Returns: None
draw_box(self, width, height, thickness, color, rounding)
Purpose: Performs draw box
Parameters:
width: Parameterheight: Parameterthickness: Parametercolor: Parameterrounding: Parameter
Returns: None
draw_ellipse(self, width, height, thickness, color)
Purpose: Performs draw ellipse
Parameters:
width: Parameterheight: Parameterthickness: Parametercolor: Parameter
Returns: None
print_graphic(self, name, scale_x, scale_y)
Purpose: Performs print graphic
Parameters:
name: Parameterscale_x: Parameterscale_y: Parameter
Returns: None
reverse_print(self, active)
Purpose: Performs reverse print
Parameters:
active: Parameter
Returns: None
run_script(self, filename)
Purpose: Performs run script
Parameters:
filename: Parameter
Returns: None
write_field_number(self, number, name, char_height, char_width, font, orientation, line_width, max_line, line_spaces, justification, hanging_indent)
Purpose: Performs write field number
Parameters:
number: Parametername: Parameterchar_height: Parameterchar_width: Parameterfont: Parameterorientation: Parameterline_width: Parametermax_line: Parameterline_spaces: Parameterjustification: Parameterhanging_indent: Parameter
Returns: None
barcode_field_default(self, module_width, bar_width_ratio, height)
Purpose: Performs barcode field default
Parameters:
module_width: Parameterbar_width_ratio: Parameterheight: Parameter
Returns: None
field_orientation(self, orientation, justification)
Purpose: sets default field orientation, and optionally, justification justification is 0 for left, 1 for right, and 2 for auto
Parameters:
orientation: Parameterjustification: Parameter
Returns: None
write_barcode(self, height, barcode_type, orientation, check_digit, print_interpretation_line, print_interpretation_line_above, magnification, errorCorrection, mask, mode)
Purpose: Performs write barcode
Parameters:
height: Parameterbarcode_type: Parameterorientation: Parametercheck_digit: Parameterprint_interpretation_line: Parameterprint_interpretation_line_above: Parametermagnification: ParametererrorCorrection: Parametermask: Parametermode: Parameter
Returns: None
dumpZPL(self)
Purpose: Performs dumpZPL
Returns: None
saveFormat(self, name)
Purpose: Performs saveFormat
Parameters:
name: Parameter
Returns: None
_print(self)
Purpose: Internal method: print
Returns: None
Required Imports
from neo4j_driver import *
import os
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
Usage Example
# Example usage:
# result = Zebra_Label(bases)
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class print_client 45.8% similar
-
class TSC_Label 45.5% similar
-
class Cassette_Printer 43.5% similar
-
function main_v117 41.1% similar
-
function get_server 39.0% similar