Barcode Generation Use Cases
Aspose.BarCode FOSS for Python (pip install aspose-barcode-foss) supports seven symbologies: Code 128, Code 39, EAN-13, EAN-8, QR Code, UPC-A, and UPC-E. This article shows practical scenarios for each.
Inventory Management
Code 128 is a common choice for inventory labels because it encodes alphanumeric data including special characters. Each item gets a unique identifier printed on a label.
from aspose_barcode_foss import BarcodeService, RenderOptions
service = BarcodeService()
# Generate a Code 128 barcode for an inventory SKU
barcode = service.generate("code128", "SKU-2026-A1234")
svg_content = barcode.to_svg(RenderOptions(scale=2.0, show_text=True))
with open("inventory_label.svg", "w") as f:
f.write(svg_content)Shipping Labels
Code 128 and Code 39 are widely used in shipping and logistics. Code 39 is simpler (uppercase letters, digits, and a few symbols) and is used in older systems. Code 128 supports a broader character set.
from aspose_barcode_foss import BarcodeService, RenderOptions
service = BarcodeService()
# Code 39 for a tracking number
barcode = service.generate("code39", "SHIP2026071234")
png_bytes = barcode.to_png(RenderOptions(dpi=300, show_text=True))
with open("shipping_label.png", "wb") as f:
f.write(png_bytes)Retail Point of Sale
EAN-13 and UPC-A are standard symbologies for retail products. EAN-13 is used internationally; UPC-A is the 12-digit North American variant.
from aspose_barcode_foss import BarcodeService, RenderOptions
service = BarcodeService()
# EAN-13 for a product barcode (12 digits; check digit auto-computed)
barcode = service.generate("ean13", "590123412345")
svg_content = barcode.to_svg(RenderOptions(scale=3.0, show_text=True))
# UPC-A for a North American product
barcode_upc = service.generate("upca", "01234567890")
svg_upc = barcode_upc.to_svg(RenderOptions(scale=3.0, show_text=True))Document Tracking
Code 128 works well for document tracking systems where each document receives a unique alphanumeric identifier.
from aspose_barcode_foss import BarcodeService, RenderOptions
service = BarcodeService()
# Generate barcodes for a batch of documents
doc_ids = ["DOC-2026-001", "DOC-2026-002", "DOC-2026-003"]
for doc_id in doc_ids:
barcode = service.generate("code128", doc_id)
svg = barcode.to_svg(RenderOptions(scale=1.5, show_text=True))
filename = f"{doc_id.lower().replace('-', '_')}.svg"
with open(filename, "w") as f:
f.write(svg)URL and Contact Encoding with QR Codes
QR Code encodes arbitrary text data including URLs, contact information, and Wi-Fi credentials.
from aspose_barcode_foss import BarcodeService, RenderOptions
service = BarcodeService()
# QR Code for a URL
barcode = service.generate("qrcode", "https://products.aspose.org/barcode/")
png_bytes = barcode.to_png(RenderOptions(scale=4.0))
with open("url_qrcode.png", "wb") as f:
f.write(png_bytes)Small-Item Labels with EAN-8 and UPC-E
EAN-8 and UPC-E are compact symbologies for items where space is limited. EAN-8 uses 7 or 8 digits; UPC-E is a compressed version of UPC-A.
from aspose_barcode_foss import BarcodeService, RenderOptions
service = BarcodeService()
# EAN-8 for a small product (7 digits; check digit auto-computed)
barcode = service.generate("ean8", "1234567")
svg = barcode.to_svg(RenderOptions(scale=2.0, show_text=True))Frequently Asked Questions
Which symbology should I choose?
- Alphanumeric data (any characters): Code 128
- Uppercase-only, legacy systems: Code 39
- Retail products (international): EAN-13 or EAN-8
- Retail products (North America): UPC-A or UPC-E
- URLs, text, binary data: QR Code
Can I generate barcodes in batch?
Yes. Create a BarcodeService instance once and call generate() in a loop. Each call returns a Barcode object that you can render independently with to_svg() or to_png().
What output formats are available?
The library renders to SVG via to_svg() and PNG via to_png(). PDF rendering is not yet implemented.