def ShiptoLabel(data,label_type):
"""Create a Commerce Show shipto label on Avery 5960
"""
import tempfile
LABELW = 2.6 * inch
LABELSEP = 2.75 * inch
LABELH = 1 * inch
# Spacing in points, bottom left = 0, 0
# top right = 612, 792
#
# Avery 5160 labels have 1/2 inch top/bottom margins, 0.18 inch left/right
# margins. Labels are 2.6" by 1". Labels abut vertically, but there is
# a .15" gutter horizontally.
#
# Top to bottom:
# 0.5 1.0 1.0 1.0 0.5
# Left to right:
# inches: 0.18 2.6 0.15 2.6 0.15 2.6 0.18
# points: 14 187 11 187 11 187 14
#
# One inch margin: 72,72 - 540,720
printer = data['printer']
tempPdfFile = tempfile.NamedTemporaryFile(prefix=label_type + '.',
suffix='.pdf',
delete=True)
canv = canvas.Canvas( tempPdfFile , pagesize=LETTER )
for pg in range(0, int(data['num_sheets'])):
for pos in range( 0, 30 ):
x, y = LabelPositionShipto( pos , LABELSEP, LABELH)
canv.roundRect( x, y, LABELW, -LABELH, 3, stroke=1, fill=0 )
canv.setFont( 'Helvetica', 10, 10 )
tx = canv.beginText( x + 5 , y - 11 )
tx.textLine(data['name'])
if data['add1']:
tx.textLine(data['add1'])
if data['add2']:
tx.textLine(data['add2'])
if data['add3']:
tx.textLine(data['add3'])
tx.textLine(data['city']+', '+data['state']+' '+data['zip'])
tx.textLine('Slsm:'+data['slsm_num']+' '+data['slsm_name'])
canv.drawText( tx )
codeImg = Code128(str(data['custshiptonum']),barWidth=.9, barHei
ght=8)
codeImg.drawOn(canv,x + 10 , y - 60, '')
canv.drawCentredString(x + (LABELW/2),y - 70 ,data['custshiptonu
m'])
canv.showPage()
canv.save()
deliver_output(printer,label_type,data['custshiptonum'],tempPdfFile.name
)