In this post we will be creating a Python script that will generate a barcode using the ReportLab library without any human-readable text. ReportLab is a powerful Python library that lets you create professional-looking PDF documents. It also provides support for generating various types of barcodes. With these barcode types, you can easily create custom barcodes to make your documents stand out and automate your business processes.
For the purpose of this example we will be creating an EAN-13 barcode. Retail and other industries commonly use the EAN-13 barcode for product identification and tracking. EAN-13 barcodes are 13 digits long, this allows EAN-13 barcodes to encode more information than other types of barcodes. (usually 12 digits long)
See the sample of Python code below where we use the ReportLab library to generate a barcode without any human-readable text present. Barcodes can sometimes include numbers and letters as a means of manual identification. This is usually the value of the barcode below.
We start below by creating a new PDF document called ‘barcode.pdf’ and assign it to the variable ‘myCanvas’. We then create a new EAN-13 barcode drawing object with the value ‘8523659632598’ and assign it to the variable ‘newBarcode’. Here the ‘
humanReadable=False‘ is passed as an argument to generate a barcode drawing without the human-readable text below it. Our ‘newBarcode’ object is then drawn onto the PDF canvas at the position (50, 50) on the page. The PDF document is then saved and the canvas is closed.
from reportlab.graphics import barcode from reportlab.pdfgen import canvas myCanvas = canvas.Canvas('barcode.pdf') newBarcode = barcode.createBarcodeDrawing('EAN13', value='8523659632598', humanReadable=False) newBarcode.drawOn(myCanvas, 50, 50) myCanvas.save()
See below a barcode with human-readable text present.
See below our barcode without any human-readable text present.
Take a look at some of our other content around the Python programming language by clicking here.