Code39条码在Python中添加到表中

时间:2013-08-29 13:46:08

标签: python barcode reportlab

我需要使用Python / Django创建Code39条形码,这些条形码必须嵌入到表格行中。

data= []

for user in users:

    individual_num = user['id']

    username = Paragraph(user['username'], styleBH)
    id = Paragraph(str(individual_num), styleBH)
    name = Paragraph('%s %s' % (user['name'], user['address']), styleBH)
    phone = Paragraph(user['phone'], styleBH)
    address = Paragraph(user['order_groups_courier'][0].user_comment, styleBH)
    purchases_count = Paragraph(str(len(user['order_groups_courier'])), styleBH)

    user_data = [ '', '%s \n %s \n %s \n %s \n %s' % (username, id, name, phone, address) ]
    data.append(user_data)

    for order_group_courier in user['order_groups_courier']:
        admin = Paragraph(order_group_courier.order_group.purchase.owner.username, styleN)
        purchase = Paragraph('%s (%s)' % (order_group_courier.order_group.purchase.name, order_group_courier.order_group_id), styleN)
        count = Paragraph(str(order_group_courier.order_group.cache_total_count), styleN)

        barcode=code39.Extended39(id, barWidth=0.4*mm, barHeight=20*mm, bearers=0.1, quiet=True, lquiet=5*mm, rquiet=5*mm)

        purchase_data = [renderPM.drawToPMCanvas(barcode), '%s %s %s' %  admin, purchase, count]
        data.append(purchase_data)

    table = Table(data, colWidths=[10* cm, 10* cm ])
    table.setStyle(TableStyle([
        ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
        ('BOX', (0,0), (-1,-1), 0.25, colors.black),
        ]))

    elements.append(KeepTogether(table))
    elements.append(Paragraph('-----', styleBH))
    data = []

doc.build(elements, canvasmaker=NumberedCanvas)

我创建了barcode = code39.Extended39,然后使用renderPM渲染它:renderPM.drawToPMCanvas(条形码),但是我收到错误“Extended39实例没有属性'renderScale'”。你能推荐我一个简单的方法吗?

0 个答案:

没有答案