Python ReportLab – Generate QR codes

In this post we will be creating a Python script that will generate QR codes using the ReportLab library. ReportLab is a powerful Python library that lets you create professional-looking PDF documents. It also provides support for generating various types of barcodes as well as QR codes. QR codes store information in 2D barcodes that smartphones can easily scan, making them a convenient way to quickly access data.

See the sample of Python code below where we use the ReportLab library to generate QR codes. We start by creating a new PDF document called ‘qrcode.pdf’ and assign it to the variable ‘myCanvas’. We then create a new QrCodeWidget object named qr_code with the URL “” as its parameter. A new Drawing object named qr_code_drawing is then created and the qr_code object is added to this. The qr_code_drawing object is then rendered to the canvas at position (50, 50). The PDF is then saved and the canvas is closed

from import Drawing
from import renderPDF
from import qr
from reportlab.pdfgen import canvas

myCanvas = canvas.Canvas("qrcode.pdf")

qr_code = qr.QrCodeWidget('')

qr_code_drawing = Drawing()


renderPDF.draw(qr_code_drawing, myCanvas, 50, 50)

An image of the barcode in our PDF can be seen below.

Python ReportLab - Generate QR codes - QR code for

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply