Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created July 16, 2026 08:01
Show Gist options
  • Select an option

  • Save aspose-com-gists/ccb471d1b8343fbd6ed928778db7f38f to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/ccb471d1b8343fbd6ed928778db7f38f to your computer and use it in GitHub Desktop.
Add Barcode to PDF in Python

Add Barcode to PDF in Python

This tutorial shows Python developers how to embed barcodes into PDF documents with Aspose.PDF for Python via .NET. Follow the instructions to generate barcode images, place them on existing PDFs, customize size and position, and handle bulk insertion.

Read the full guide here: https://blog.aspose.com/pdf/add-barcode-to-pdf-in-python/

# Complete working example: add barcode to an existing PDF
from asposebarcode import BarcodeGenerator, EncodeTypes
from asposebarcode.generator import BarCodeImageFormat
from asposepdf import Document, ImageStamp
# 1. Generate barcode image in memory
barcode_generator = BarcodeGenerator(EncodeTypes.CODE_128, "INV-2023-001")
barcode_generator.parameters.image.width = 300
barcode_generator.parameters.image.height = 100
barcode_stream = barcode_generator.generate_barcode_image(BarCodeImageFormat.PNG)
# 2. Load the PDF you want to modify
pdf_document = Document("invoice_template.pdf")
# 3. Add the barcode to the first page
page = pdf_document.pages[0]
stamp = ImageStamp(barcode_stream)
stamp.x = 50 # X coordinate (points)
stamp.y = 700 # Y coordinate (points)
stamp.width = 300
stamp.height = 100
page.add_stamp(stamp)
# 4. Save the updated PDF
pdf_document.save("invoice_with_barcode.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment