def createBarCodes(): """ Create barcode examples and embed in a PDF """ c = canvas.Canvas("barcodes.pdf", pagesize=A4) barcode_value = "1234567890" barcode39 = code39.Extended39(barcode_value) barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1) # code93 also has an Extended and MultiWidth version barcode93 = code93.Standard93(barcode_value) barcode128 = code128.Code128(barcode_value) # the multiwidth barcode appears to be broken #barcode128Multi = code128.MultiWidthBarcode(barcode_value) barcode_usps = usps.POSTNET("50158-9999") codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps] x = 1 * mm y = 285 * mm x1 = 6.4 * mm for code in codes: code.drawOn(c, x, y) y = y - 15 * mm # draw the eanbc8 code barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value) bounds = barcode_eanbc8.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(50, 10) d.add(barcode_eanbc8) renderPDF.draw(d, c, 15, 555) # draw the eanbc13 code barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value) bounds = barcode_eanbc13.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(50, 10) d.add(barcode_eanbc13) renderPDF.draw(d, c, 15, 465) # draw a QR code qr_code = qr.QrCodeWidget( 'https://stackoverflow.com/questions/10147455/how-to-send-an-email-with-gmail-as-provider-using-python' ) bounds = qr_code.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(45, 45, transform=[45. / width, 0, 0, 45. / height, 0, 0]) d.add(qr_code) renderPDF.draw(d, c, 15, 405) c.save()
def createBarCodes(): """ Create barcode examples and embed in a PDF """ c = canvas.Canvas("barcodes.pdf", pagesize=letter) barcode_value = "12345678999M" barcode39 = code39.Extended39(barcode_value) barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1) # code93 also has an Extended and MultiWidth version barcode93 = code93.Standard93(barcode_value) barcode128 = code128.Code128(barcode_value) # the multiwidth barcode appears to be broken #barcode128Multi = code128.MultiWidthBarcode(barcode_value) barcode_usps = usps.POSTNET("50158-9999") codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps] x = 1 * mm y = 260 * mm x1 = 6.4 * mm for code in codes: code.drawOn(c, x, y) y = y - 30 * mm barcode_value = "123456789990" # draw the eanbc8 code barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value) bounds = barcode_eanbc8.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(50, 10) d.add(barcode_eanbc8) renderPDF.draw(d, c, 150 * mm, 150 * mm) # # draw the eanbc13 code barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value) bounds = barcode_eanbc13.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(50, 10) d.add(barcode_eanbc13) renderPDF.draw(d, c, 150 * mm, 100 * mm) # # draw a QR code qr_code = qr.QrCodeWidget('www.ghf.com') bounds = qr_code.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(45, 45, transform=[45. / width, 0, 0, 45. / height, 0, 0]) d.add(qr_code) renderPDF.draw(d, c, 150 * mm, 50 * mm) c.save()
def primera_hoja_layout(self, canvas, doc): canvas.saveState() canvas.setPageSize(self.pagesize) logo = 'static/fondo1.jpg' canvas.drawImage(logo, 0 * cm, 0 * cm, width=(8.5 * cm), height=(5.28 * cm)) foto = str(self.licencia.persona.foto) canvas.drawImage(foto, 3 * mm, 1.3 * cm, width=(2 * cm), height=(2.5 * cm)) foto = str(self.licencia.persona.firma) canvas.drawImage(foto, 51 * mm, 2.5 * cm, width=(2.6 * cm), height=(1 * cm)) categoria = Paragraph(u'Categoría', negrita_custom(8.5, TA_LEFT)) w, h = categoria.wrap(doc.width, doc.topMargin) categoria.drawOn(canvas, 52 * mm, 16.9 * mm) categoria = Paragraph(self.licencia.clase, normal_custom(8.5, TA_LEFT)) w, h = categoria.wrap(doc.width, doc.topMargin) categoria.drawOn(canvas, 56 * mm, 12.5 * mm) categoria = Paragraph(self.licencia.categoria, normal_custom(8.5, TA_LEFT)) w, h = categoria.wrap(doc.width, doc.topMargin) categoria.drawOn(canvas, 53 * mm, 12.5 * mm) categoria = Paragraph(u'F. Revalidación', negrita_custom(8.5, TA_LEFT)) w, h = categoria.wrap(doc.width, doc.topMargin) categoria.drawOn(canvas, 52 * mm, 8.2 * mm) categoria = Paragraph( self.licencia.fecha_revalidacion.strftime('%d/%m/%Y'), normal_custom(8.5, TA_LEFT)) w, h = categoria.wrap(doc.width, doc.topMargin) categoria.drawOn(canvas, 53 * mm, 4 * mm) barcode = code93.Standard93(self.licencia.persona.dni, barWidth=0.55, barHeight=7.5 * mm, stop=1) w, h = barcode.wrap(doc.width, doc.topMargin) barcode.drawOn(canvas, -4 * mm, 6 * mm) canvas.restoreState()
def _flowable(self, node, extra_style=None): if node.tag == 'para': style = self.styles.para_style_get(node) if extra_style: style.__dict__.update(extra_style) result = [] for i in self._textual(node).split('\n'): result.append( platypus.Paragraph( i, style, **(utils.attr_get(node, [], {'bulletText': 'str'})))) return result elif node.tag == 'barCode': try: from reportlab.graphics.barcode import code128 from reportlab.graphics.barcode import code39 from reportlab.graphics.barcode import code93 from reportlab.graphics.barcode import common from reportlab.graphics.barcode import fourstate from reportlab.graphics.barcode import usps except Exception, e: return None args = utils.attr_get( node, [], { 'ratio': 'float', 'xdim': 'unit', 'height': 'unit', 'checksum': 'int', 'quiet': 'int', 'width': 'unit', 'stop': 'bool', 'bearers': 'int', 'barWidth': 'float', 'barHeight': 'float' }) codes = { 'codabar': lambda x: common.Codabar(x, **args), 'code11': lambda x: common.Code11(x, **args), 'code128': lambda x: code128.Code128(x, **args), 'standard39': lambda x: code39.Standard39(x, **args), 'standard93': lambda x: code93.Standard93(x, **args), 'i2of5': lambda x: common.I2of5(x, **args), 'extended39': lambda x: code39.Extended39(x, **args), 'extended93': lambda x: code93.Extended93(x, **args), 'msi': lambda x: common.MSI(x, **args), 'fim': lambda x: usps.FIM(x, **args), 'postnet': lambda x: usps.POSTNET(x, **args), } code = 'code128' if node.get('code'): code = node.get('code').lower() return codes[code](self._textual(node))
def code93_demo(barcode_value): doc = SimpleDocTemplate('code93_demo.pdf') styles = getSampleStyleSheet() flowables = [] flowables.append(Paragraph('Code 93 Standard:', style=styles['Normal'])) barcode93Std = code93.Standard93() flowables.append(barcode93Std) flowables.append(Spacer(0, 25)) flowables.append(Paragraph('Code 93 Extended:', style=styles['Normal'])) barcode93 = code93.Extended93(barcode_value) flowables.append(barcode93) doc.build(flowables)
def createBarCodes(c): barcode_value = '0112358' barcode39 = code39.Extended39(barcode_value) barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1) barcode93 = code93.Standard93(barcode_value) barcode128 = code128.Code128(barcode_value) # barcode128Multi = code128.MultiWidthBarcode(barcode_value) barcode_usps = usps.POSTNET('50158-9999') codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps] x = 1 * mm y = 285 * mm for code in codes: code.drawOn(c, x, y) y = y - 15 * mm barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value) d = Drawing(50, 10) d.add(barcode_eanbc8) renderPDF.draw(d, c, 15, 555) barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value) d = Drawing(50, 10) d.add(barcode_eanbc13) renderPDF.draw(d, c, 15, 465) qr_code = qr.QrCodeWidget('http://www.baidu.com') bounds = qr_code.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(45, 45, transform=[45./width, 0,0,45./height, 0, 0]) d.add(qr_code) renderPDF.draw(d, c, 15, 405)
def _flowable(self, node, extra_style=None): if node.tag=='pto': return self._pto(node) if node.tag=='para': style = self.styles.para_style_get(node) if extra_style: style.__dict__.update(extra_style) result = [] for i in self._textual(node).split('\n'): result.append(platypus.Paragraph(i, style, **(utils.attr_get(node, [], {'bulletText':'str'})))) return result elif node.tag=='barCode': try: from reportlab.graphics.barcode import code128 from reportlab.graphics.barcode import code39 from reportlab.graphics.barcode import code93 from reportlab.graphics.barcode import common from reportlab.graphics.barcode import fourstate from reportlab.graphics.barcode import usps from reportlab.graphics.barcode import createBarcodeDrawing except ImportError: _logger.warning("Cannot use barcode renderers:", exc_info=True) return None args = utils.attr_get(node, [], {'ratio':'float','xdim':'unit','height':'unit','checksum':'int','quiet':'int','width':'unit','stop':'bool','bearers':'int','barWidth':'float','barHeight':'float'}) codes = { 'codabar': lambda x: common.Codabar(x, **args), 'code11': lambda x: common.Code11(x, **args), 'code128': lambda x: code128.Code128(str(x), **args), 'standard39': lambda x: code39.Standard39(str(x), **args), 'standard93': lambda x: code93.Standard93(str(x), **args), 'i2of5': lambda x: common.I2of5(x, **args), 'extended39': lambda x: code39.Extended39(str(x), **args), 'extended93': lambda x: code93.Extended93(str(x), **args), 'msi': lambda x: common.MSI(x, **args), 'fim': lambda x: usps.FIM(x, **args), 'postnet': lambda x: usps.POSTNET(x, **args), 'ean13': lambda x: createBarcodeDrawing('EAN13', value=str(x), **args), 'qrcode': lambda x: createBarcodeDrawing('QR', value=x, **args), } code = 'code128' if node.get('code'): code = node.get('code').lower() return codes[code](self._textual(node)) elif node.tag=='name': self.styles.names[ node.get('id')] = node.get('value') return None elif node.tag=='xpre': style = self.styles.para_style_get(node) return platypus.XPreformatted(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str','dedent':'int','frags':'int'}))) elif node.tag=='pre': style = self.styles.para_style_get(node) return platypus.Preformatted(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str','dedent':'int'}))) elif node.tag=='illustration': return self._illustration(node) elif node.tag=='blockTable': return self._table(node) elif node.tag=='title': styles = reportlab.lib.styles.getSampleStyleSheet() style = styles['Title'] return platypus.Paragraph(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str'}))) elif re.match('^h([1-9]+[0-9]*)$', (node.tag or '')): styles = reportlab.lib.styles.getSampleStyleSheet() style = styles['Heading'+str(node.tag[1:])] return platypus.Paragraph(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str'}))) elif node.tag=='image': image_data = False if not node.get('file'): if node.get('name'): if node.get('name') in self.doc.images: _logger.debug("Image %s read ", node.get('name')) image_data = self.doc.images[node.get('name')].read() else: _logger.warning("Image %s not defined", node.get('name')) return False else: import base64 newtext = node.text if self.localcontext: newtext = utils._process_text(self, node.text or '') image_data = base64.decodestring(newtext) if not image_data: _logger.debug("No inline image data") return False image = StringIO(image_data) else: _logger.debug("Image get from file %s", node.get('file')) image = _open_image(node.get('file'), path=self.doc.path) return platypus.Image(image, mask=(250,255,250,255,250,255), **(utils.attr_get(node, ['width','height']))) elif node.tag=='spacer': if node.get('width'): width = utils.unit_get(node.get('width')) else: width = utils.unit_get('1cm') length = utils.unit_get(node.get('length')) return platypus.Spacer(width=width, height=length) elif node.tag=='section': return self.render(node) elif node.tag == 'pageNumberReset': return PageReset() elif node.tag in ('pageBreak', 'nextPage'): return platypus.PageBreak() elif node.tag=='condPageBreak': return platypus.CondPageBreak(**(utils.attr_get(node, ['height']))) elif node.tag=='setNextTemplate': return platypus.NextPageTemplate(str(node.get('name'))) elif node.tag=='nextFrame': return platypus.CondPageBreak(1000) # TODO: change the 1000 ! elif node.tag == 'setNextFrame': from reportlab.platypus.doctemplate import NextFrameFlowable return NextFrameFlowable(str(node.get('name'))) elif node.tag == 'currentFrame': from reportlab.platypus.doctemplate import CurrentFrameFlowable return CurrentFrameFlowable(str(node.get('name'))) elif node.tag == 'frameEnd': return EndFrameFlowable() elif node.tag == 'hr': width_hr=node.get('width') or '100%' color_hr=node.get('color') or 'black' thickness_hr=node.get('thickness') or 1 lineCap_hr=node.get('lineCap') or 'round' return platypus.flowables.HRFlowable(width=width_hr,color=color.get(color_hr),thickness=float(thickness_hr),lineCap=str(lineCap_hr)) else: sys.stderr.write('Warning: flowable not yet implemented: %s !\n' % (node.tag,)) return None
def run(): c = reportlab.pdfgen.canvas.Canvas('barcodetest.pdf', pagesize=pagesizes.A4) framePage(c, 'Hebi-No-Shisho Barcode Test Page' ) y = 700 yd = 50 xb = 40 xs = 240 y = y-yd mybarcode = code39.Standard39(barWidth=inch * 0.010, value="CD3910", checksum=0) mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard39 10 mil' % mybarcode.encoded) y = y-yd mybarcode = code39.Standard39(barWidth=inch * 0.015, value="CD3915", checksum=0) mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard39 15 mil' % mybarcode.encoded) y = y-yd mybarcode = code39.Standard39(barWidth=inch * 0.020, value="CD3930", checksum=0) mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard39 20 mil' % mybarcode.encoded) y = y-yd mybarcode = code93.Standard93(barWidth=inch * 0.010, value="CD9310") mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard93 10 mil' % mybarcode.encoded) y = y-yd mybarcode = code93.Standard93(barWidth=inch * 0.015, value="CD9315") mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard93 15 mil' % mybarcode.encoded) y = y-yd mybarcode = code93.Standard93(barWidth=inch * 0.020, value="CD9320") mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard93 20 mil' % mybarcode.encoded) y = y-yd mybarcode = code128.Code128(barWidth=inch * 0.010, value="C12810") mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard128 10 mil' % mybarcode.value) y = y-yd mybarcode = code128.Code128(barWidth=inch * 0.015, value="C12815") mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard128 15 mil' % mybarcode.value) y = y-yd mybarcode = code128.Code128(barWidth=inch * 0.020, value="C12820") mybarcode.drawOn(c, xb, y) c.drawString(xs, y, '%s - Standard128 20 mil' % mybarcode.value) y = y-yd-10 mydrawing = Drawing() mybarcode = eanbc.Ean13BarcodeWidget(barHeight=inch * 0.5, barWidth=inch * 0.015, value="123456789012") mydrawing.add(mybarcode) mydrawing.drawOn(c, xb, y) c.drawString(xs, y, 'EAN13') c.save()
def createBarCodes(): """ Create barcode examples and embed in a PDF """ #Taking the filename from the user name = input('enter a filename(.pdf) :') c = canvas.Canvas(name, pagesize=letter) #Setting the 10 digit barcode value barcode_value = str(random_with_N_digits(12)) barcode39 = code39.Extended39(barcode_value) barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1) # code93 also has an Extended and MultiWidth version barcode93 = code93.Standard93(barcode_value) barcode128 = code128.Code128(barcode_value) # the multiwidth barcode appears to be broken #barcode128Multi = code128.MultiWidthBarcode(barcode_value) codes = [barcode39, barcode39Std, barcode93, barcode128] x = 1 * mm y = 285 * mm x1 = 6.4 * mm for code in codes: code.drawOn(c, x, y) y = y - 15 * mm # draw the eanbc8 code barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value) bounds = barcode_eanbc8.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(50, 10) d.add(barcode_eanbc8) renderPDF.draw(d, c, 15, 555) # draw the eanbc13 code barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value) bounds = barcode_eanbc13.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(50, 10) d.add(barcode_eanbc13) renderPDF.draw(d, c, 15, 465) # draw a QR code qr_code = qr.QrCodeWidget(barcode_value) bounds = qr_code.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(45, 45, transform=[45. / width, 0, 0, 45. / height, 0, 0]) d.add(qr_code) renderPDF.draw(d, c, 15, 405) c.save()
def report(self, reporters): # Create the PDF object, using the response object as its "file." pdf = canvas.Canvas(self.response) times_bold = ttfonts.TTFont('TimesBold', 'Times New Roman Cyr Bold.ttf') times = ttfonts.TTFont('Times', 'Times New Roman Cyr.ttf') pdfmetrics.registerFont(times_bold) pdfmetrics.registerFont(times) saved = False access_cover = ImageReader(ACCESS_COVER) times_bold = ttfonts.TTFont('TimesBold', 'Times New Roman Cyr Bold.ttf') times = ttfonts.TTFont('Times', 'Times New Roman Cyr.ttf') pdfmetrics.registerFont(times_bold) pdfmetrics.registerFont(times) count = 1 margin = self.margins() for reporter in reporters: if count % 5 == 0: pdf.showPage() margin = self.margins() saved = True else: saved = False pdf.drawImage(access_cover, 3 * cm, margin['main_cover'] * cm, 13.75 * cm, 4.5 * cm) try: reporter_face = ImageReader(reporter.image_crop) except: reporter_face = ImageReader('main/static/main/img/unknown.jpg') pdf.drawImage(reporter_face, 3.2 * cm, margin['face'] * cm, 2.83 * cm, 3.7 * cm) watermark = ImageReader('access_watermark.png') pdf.drawImage(watermark, 3.02 * cm, margin['watermark'] * cm, 4.3 * cm, 4.45 * cm, mask='auto') pdf.setFont("TimesBold", 13) if len(reporter.surname) > 13: pdf.setFont("TimesBold", 11) pdf.drawString(6.3 * cm, margin['surname'] * cm, reporter.surname) pdf.drawString(6.3 * cm, margin['name'] * cm, reporter.name) pdf.drawString(6.3 * cm, margin['lastname'] * cm, reporter.lastname) pdf.setFont("TimesBold", 11) pdf.setFillColorRGB(255, 0, 0) if len(reporter.post) < 16: pdf.drawString(6.3 * cm, margin['post'] * cm, reporter.post) else: pdf.drawString(6.3 * cm, margin['post'] * cm, reporter.post[0:16]) pdf.drawString(6.3 * cm, (margin['post'] - 0.42) * cm, reporter.post[16:32]) pdf.setFillColorRGB(0, 0, 161) if len(reporter.massmedia.__str__()) < 16: pdf.drawString(6.3 * cm, margin['massmedia'] * cm, reporter.massmedia.__str__()) else: pdf.drawString(6.3 * cm, margin['massmedia'] * cm, reporter.massmedia.__str__()[0:17]) pdf.drawString(6.3 * cm, (margin['massmedia'] - 0.42) * cm, reporter.massmedia.__str__()[16:32]) unique_num = randint(100001, 999999) unique_str = "PR-%s-%s" % (16, unique_num) pdf.setFont("TimesBold", 9) pdf.setFillColorRGB(255, 0, 0) pdf.drawString(3.6 * cm, margin['u_str_left'] * cm, unique_str) pdf.setFillColorRGB(0, 0, 161) pdf.drawString(14.35 * cm, margin['u_str_right'] * cm, unique_str) # qrw = QrCodeWidget('Helo World!') # qrw.draw() barcode = code93.Standard93(str(unique_num), barWidth=0.25 * mm, barHeight=15 * mm) # drawOn puts the barcode on the canvas at the specified coordinates pdf.setFillColorRGB(0, 0, 0) barcode.drawOn(pdf, 9.5 * cm, margin['barcode'] * cm) pdf.drawString(10.8 * cm, margin['barcode_num'] * cm, str(unique_num)) for key, value in margin.items(): margin[key] = value - 5 reporter.printed = True reporter.save() count += 1 if not saved: pdf.showPage() pdf.save() return self.response
for i in L.iter_label(data): # draw text if L.new_page: c.setFillColorRGB(1,0,0) c.setFont("Helvetica-Bold", size=6) c.drawString(-10,L.sizeY*-1-40, "This text is on every page. Attention, this position is relativ to the first label." + " "*27 + "Page " + str(int(i["id"]/8+1))) c.setFillColorRGB(*i["rgb"]) c.setFont("Helvetica-Bold", size=8) c.drawCentredString(L.sizeX / 2 , 27, i["color"]) c.setFillColorRGB(0, 0, 0) c.setFont("Courier", size=7) c.drawCentredString(L.sizeX/2, 7, "ID: " + str(i["id"])) # draw barcodes #bc = code39.Extended39("ID%.6i" % i["id"], barWidth=0.30, barHeight=10) #bc = code128.Code128("ID%.6i" % i["id"], barWidth=0.45, barHeight=10 bc = code93.Standard93("ID%.6i" % i["id"], barWidth=0.33, barHeight=8) bc.drawOn(c, -10, 14 ) # draw QR-code qr_code = qr.QrCodeWidget("WEB:www.example.com\nACCESS:%s\nID%.6i\nTS:%s" % (i["color"],i["id"],datetime.now().strftime("%m/%d/%Y, %H:%M:%S"))) bounds = qr_code.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] dr = Drawing(0, 0, transform=[25. / width, 0, 0, 25. / height, 0, 0]) dr.add(qr_code) renderPDF.draw(dr, c, L.sizeX/2-12, 35) # draw hole c.circle(7, L.sizeY-7, 2.5) # draw image c.drawImage("star.jpg",5.0,27.0,width=6,height=6, preserveAspectRatio=True, anchor='c') L.save()
def createBarCodes(): """ Create barcode examples and embed in a PDF """ c = canvas.Canvas("barcodes.pdf", pagesize=letter) barcode_value = [ '0004-0000000001', '0004-0000000002', '0004-0000000003', '0004-0000000004', '0004-0000000005', '0004-0000000013', '0004-0000000028', '0004-0000000029', '0004-0000000030', '0004-0000000031', ] #barcode_value = "1234567890" barcode_value = "0004-0000000001" barcode39 = code39.Extended39(barcode_value, humanReadable=True) barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1, humanReadable=True) # code93 also has an Extended and MultiWidth version barcode93 = code93.Standard93(barcode_value, humanReadable=True) barcode128 = code128.Code128(barcode_value, humanReadable=True) # the multiwidth barcode appears to be broken #barcode128Multi = code128.MultiWidthBarcode(barcode_value) barcode_usps = usps.POSTNET("50158-9999") codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps] x = 1 * mm y = 285 * mm x1 = 6.4 * mm for code in codes: code.drawOn(c, x, y) y = y - 15 * mm # draw the eanbc8 code """ barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value) bounds = barcode_eanbc8.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(50, 10) d.add(barcode_eanbc8) renderPDF.draw(d, c, 15, 555) """ # draw the eanbc13 code """ barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value) bounds = barcode_eanbc13.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(50, 10) d.add(barcode_eanbc13) renderPDF.draw(d, c, 15, 465) """ c.save()