print incremental sequence in labels
This commit is contained in:
parent
d3ca5f342e
commit
eb7b36f54e
1 changed files with 13 additions and 7 deletions
|
@ -14,6 +14,7 @@ import cups
|
||||||
import tempfile
|
import tempfile
|
||||||
from PIL import Image, ImageFont, ImageDraw
|
from PIL import Image, ImageFont, ImageDraw
|
||||||
|
|
||||||
|
KEEP_IMG = False
|
||||||
LABEL_WIDTH = 13488
|
LABEL_WIDTH = 13488
|
||||||
LABEL_HEIGHT = 3744
|
LABEL_HEIGHT = 3744
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ FONT_TEXT_ENCODING = 'latin-1'
|
||||||
FONT_BARCODE = 'free3of9.ttf'
|
FONT_BARCODE = 'free3of9.ttf'
|
||||||
|
|
||||||
PRINTER_NAME = None
|
PRINTER_NAME = None
|
||||||
|
#PRINTER_NAME = 'DYMO_LabelWriter_450'
|
||||||
|
|
||||||
|
|
||||||
def _get_resource(filename):
|
def _get_resource(filename):
|
||||||
|
@ -33,7 +34,7 @@ def build_label(w, h, barcode_text, line1, line2, font_text=FONT_TEXT, font_barc
|
||||||
barcode_text = "*" + barcode_text + "*"
|
barcode_text = "*" + barcode_text + "*"
|
||||||
line1 = unicode(line1, 'utf-8').encode(FONT_TEXT_ENCODING, 'ignore')
|
line1 = unicode(line1, 'utf-8').encode(FONT_TEXT_ENCODING, 'ignore')
|
||||||
line2 = unicode(line2, 'utf-8').encode(FONT_TEXT_ENCODING, 'ignore')
|
line2 = unicode(line2, 'utf-8').encode(FONT_TEXT_ENCODING, 'ignore')
|
||||||
fontbar = ImageFont.truetype(_get_resource(font_barcode), 1200)
|
fontbar = ImageFont.truetype(_get_resource(font_barcode), 2200)
|
||||||
fontnorm = ImageFont.truetype(_get_resource(font_text), 780)
|
fontnorm = ImageFont.truetype(_get_resource(font_text), 780)
|
||||||
image = Image.new('RGB', (w, h), (255, 255, 255))
|
image = Image.new('RGB', (w, h), (255, 255, 255))
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
|
@ -42,8 +43,12 @@ def build_label(w, h, barcode_text, line1, line2, font_text=FONT_TEXT, font_barc
|
||||||
wnorm2, hnorm2 = draw.textsize(line2, font=fontnorm)
|
wnorm2, hnorm2 = draw.textsize(line2, font=fontnorm)
|
||||||
draw.text(((w-wnorm1)/2, -1200+(h-hnorm1)/2), line1, (0, 0, 0), font=fontnorm)
|
draw.text(((w-wnorm1)/2, -1200+(h-hnorm1)/2), line1, (0, 0, 0), font=fontnorm)
|
||||||
draw.text(((w-wnorm2)/2, -450+(h-hnorm2)/2), line2, (0, 0, 0), font=fontnorm)
|
draw.text(((w-wnorm2)/2, -450+(h-hnorm2)/2), line2, (0, 0, 0), font=fontnorm)
|
||||||
draw.text(((w-wbar)/2, 750+(h-hbar)/2), barcode_text, (0, 0, 0), font=fontbar)
|
draw.text(((w-wbar)/2, 850+(h-hbar)/2), barcode_text, (0, 0, 0), font=fontbar)
|
||||||
|
if not KEEP_IMG:
|
||||||
tmpfile = tempfile.NamedTemporaryFile(prefix='eventman_print_label_', suffix='.png')
|
tmpfile = tempfile.NamedTemporaryFile(prefix='eventman_print_label_', suffix='.png')
|
||||||
|
else:
|
||||||
|
tmpfile = tempfile.mktemp(prefix='eventman_print_label_', suffix='.png')
|
||||||
|
tmpfile = open(tmpfile, 'wb')
|
||||||
image.save(tmpfile, dpi=[600, 300], format='png')
|
image.save(tmpfile, dpi=[600, 300], format='png')
|
||||||
return tmpfile
|
return tmpfile
|
||||||
|
|
||||||
|
@ -59,8 +64,9 @@ def run():
|
||||||
sys.stdin.read()
|
sys.stdin.read()
|
||||||
name = ' '.join([os.environ.get('NAME') or '', os.environ.get('SURNAME') or ''])
|
name = ' '.join([os.environ.get('NAME') or '', os.environ.get('SURNAME') or ''])
|
||||||
company = os.environ.get('COMPANY') or ''
|
company = os.environ.get('COMPANY') or ''
|
||||||
person_id = os.environ.get('PERSON_ID', '').upper()
|
# Print the decimal value SEQ as an hex of at least 6 digits.
|
||||||
label_file = build_label(LABEL_WIDTH, LABEL_HEIGHT, person_id, name, company)
|
seq = os.environ.get('SEQ_HEX', '0')
|
||||||
|
label_file = build_label(LABEL_WIDTH, LABEL_HEIGHT, seq, name, company)
|
||||||
print_label(label_file, name)
|
print_label(label_file, name)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue