Skip to content

Instantly share code, notes, and snippets.

@mmmattos
Created May 19, 2014 03:30
Show Gist options
  • Save mmmattos/8d460f99a0a078e8565a to your computer and use it in GitHub Desktop.
Save mmmattos/8d460f99a0a078e8565a to your computer and use it in GitHub Desktop.
Creating Barcodes for Brazilian Banking using Python and Reportlab
# Sample i2of5 barcode generation.
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
from reportlab.graphics.barcode.common import I2of5
c=canvas.Canvas("barcode_example.pdf",pagesize=A4)
tb=0.254320987654 * mm # thin bar
bh=20 * mm # bar height
bcl=180 * mm # barcode length
digits = "04198000000000000002131008609000127646104171"
bc=I2of5(digits,barWidth=tb,ratio=3,barHeight=bh,bearers=0,quiet=0,checksum=0)
# Adjust the width
tb = (tb * bcl) / bc.width
bc.__init__(digits, barWidth=tb)
# Render the bc image 5mm from bottom of the page.
bc.drawOn(c,5*mm,5*mm)
c.showPage()
c.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment