Compare Pastes
Differences between the pastes #953 (Jul 28, 2010 11:15:06 AM) and #954 (Jul 28, 2010 11:48:18 AM). Download as unified diff.
| 1 | def ShiptoLabel(data,label_type): | |
|---|---|---|
| 2 | """Create a Commerce Show shipto label on Avery 5960 | |
| 3 | """ | |
| 4 | import tempfile | |
| 5 | ||
| 6 | LABELW = 2.6 * inch | |
| 7 | LABELSEP = 2.75 * inch | |
| 8 | LABELH = 1 * inch | |
| 9 | ||
| 10 | # Spacing in points, bottom left = 0, 0 | |
| 11 | # top right = 612, 792 | |
| 12 | # | |
| 13 | # Avery 5160 labels have 1/2 inch top/bottom margins, 0.18 inch left/right | |
| 14 | # margins. Labels are 2.6" by 1". Labels abut vertically, but there is | |
| 15 | # a .15" gutter horizontally. | |
| 16 | # | |
| 17 | # Top to bottom: | |
| 18 | # 0.5 1.0 1.0 1.0 0.5 | |
| 19 | # Left to right: | |
| 20 | # inches: 0.18 2.6 0.15 2.6 0.15 2.6 0.18 | |
| 21 | # points: 14 187 11 187 11 187 14 | |
| 22 | # | |
| 23 | # One inch margin: 72,72 - 540,720 | |
| 24 | ||
| 25 | printer = data['printer'] | |
| 26 | ||
| 27 | tempPdfFile = tempfile.NamedTemporaryFile(prefix=label_type + '.', | |
| 28 | suffix='.pdf', | |
| 29 | delete=True) | |
| 30 | canv = canvas.Canvas( tempPdfFile , pagesize=LETTER ) | |
| 31 | ||
| 32 | for pg in range(0, int(data['num_sheets'])): | |
| 33 | for pos in range( 0, 30 ): | |
| 34 | x, y = LabelPositionShipto( pos , LABELSEP, LABELH) | |
| 35 | canv.roundRect( x, y, LABELW, -LABELH, 3, stroke=1, fill=0 ) | |
| 36 | canv.setFont( 'Helvetica', 10, 10 ) | |
| 37 | ||
| 38 | tx = canv.beginText( x + 5 , y - 11 ) | |
| 39 | tx.textLine(data['name']) | |
| 40 | if data['add1']: | |
| 41 | tx.textLine(data['add1']) | |
| 42 | if data['add2']: | |
| 43 | tx.textLine(data['add2']) | |
| 44 | if data['add3']: | |
| 45 | tx.textLine(data['add3']) | |
| 46 | tx.textLine(data['city']+', '+data['state']+' '+data['zip']) | |
| 47 | tx.textLine('Slsm:'+data['slsm_num']+' '+data['slsm_name']) | |
| 48 | canv.drawText( tx ) | |
| 1 | === BEFORE ===== | |
| 49 | 2 | |
| 50 | 3 | codeImg = Code128(str(data['custshiptonum']),barWidth=.9, barHei |
| 51 | 4 | ght=8) |
| 52 | 5 | codeImg.drawOn(canv,x + 10 , y - 60, '') |
| … | ||
| 56 | 9 | canv.save() |
| 57 | 10 | |
| 58 | 11 | deliver_output(printer,label_type,data['custshiptonum'],tempPdfFile.name |
| 59 | 12 | ) |
| 13 | ==== after ====== | |
| 14 | 156 if page_row_ctr == ROWS_PER_PG: | |
| 15 | 157 canv.showPage() | |
| 16 | 158 page_row_ctr = 0 | |
| 17 | 159 | |
| 18 | 160 canv.save() | |
| 19 | 161 tfname = tempPdfFile.name | |
| 20 | 162 tempPdfFile.close() | |
| 21 | 163 deliver_output(printer,label_type, mk_timestamp(),tfname ) | |