Skip to content

Barcodes

Code 39

Here is an example on how to generate a Code 39 barcode:

pdf = FPDF()
pdf.add_page()
pdf.code39("fpdf2", x=50, y=50, w=4, h=20)
pdf.output("code39.pdf")

Output preview:

Interleaved 2 of 5

Here is an example on how to generate an Interleaved 2 of 5 barcode:

pdf = FPDF()
pdf.add_page()
pdf.interleaved2of5("1337", x=50, y=50, w=4, h=20)
pdf.output("interleaved2of5.pdf")

Output preview:

PDF-417

Here is an example on how to generate a PDF-417 barcode using the pdf417 lib:

from pdf417 import encode, render_image

pdf = FPDF()
pdf.add_page()
img = render_image(encode("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam."))
pdf.image(img, x=10, y=50)
pdf.output("pdf417.pdf")

Output preview:

QRCode

Here is an example on how to generate a QR Code using the python-qrcode lib:

import qrcode

pdf = FPDF()
pdf.add_page()
img = qrcode.make("fpdf2")
pdf.image(img.get_image(), x=50, y=50)
pdf.output("qrcode.pdf")

Output preview: