#!/usr/bin/python # # requires zint binary from zint package # from subprocess import Popen, PIPE import sys svghead = """ """ svgfoot = """ """ width = 5 scalex = 0.8 scaley = 0.8 p = 0 i = 0 j = 0 f = None lines = sys.stdin.readlines() for idx in xrange(len(lines)): items = lines[idx].strip().split(';') if idx % 30 == 0: if f and not f.closed: f.write(svgfoot) f.close() f = open('barcodes' + str(p) + '.svg','w') p += 1 i = 0 j = 0 f.write(svghead) elem = Popen(('./zint','--directsvg','--notext', '-d', items[1]), stdout = PIPE).communicate()[0].split('\n') elem = elem[8:-2] elem[0] = elem[0].replace('id="barcode"', 'transform="matrix(%f,0,0,%f,%f,%f)"' % (scalex, scaley, 50+i*140 , 180+j*140) ) elem.insert(-1, ' %s' % items[0]) f.write('\n'.join(elem)+'\n\n') i += 1 if i >= width: i = 0 j += 1 if not f.closed: f.write(svgfoot) f.close()