Created
May 19, 2014 03:30
-
-
Save mmmattos/8d460f99a0a078e8565a to your computer and use it in GitHub Desktop.
Creating Barcodes for Brazilian Banking using Python and Reportlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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