Skip to content

Instantly share code, notes, and snippets.

@luxinyan
Created April 23, 2014 07:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save luxinyan/11205358 to your computer and use it in GitHub Desktop.
Save luxinyan/11205358 to your computer and use it in GitHub Desktop.
Generate barcode with reportlab.
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
#I"ll be generating code39 barcodes, others are available
from reportlab.graphics.barcode import code39
# generate a canvas (A4 in this case, size doesn"t really matter)
c=canvas.Canvas("barcode_example.pdf",pagesize=A4)
# create a barcode object
# (is not displayed yet)
# The encode text is "123456789"
# barHeight encodes how high the bars will be
# barWidth encodes how wide the "narrowest" barcode unit is
barcode=code39.Extended39("123456789",barWidth=0.5*mm,barHeight=20*mm)
# drawOn puts the barcode on the canvas at the specified coordinates
barcode.drawOn(c,100*mm,100*mm)
# now create the actual PDF
c.showPage()
c.save()
@Irbingou
Copy link

Irbingou commented May 6, 2020

Tks :)
I didn't need the barwidth and barheight, the image size is very long
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment