pdf417gen
raw JSON → 0.8.1 verified Fri May 01 auth: no python
A pure Python library for generating PDF417 2D barcodes. Version 0.8.1 (latest) supports encoding text, bytes, and numbers into PDF417 barcodes, with output as PIL Images, SVG strings, or list of boolean rows. Requires Python >=3.8.
pip install pdf417gen Common errors
error NameError: name 'render_image' is not defined ↓
cause Forgot to import render_image, or imported from wrong module.
fix
Use:
from pdf417gen import render_image error ModuleNotFoundError: No module named 'PIL' ↓
cause Pillow is required for render_image but not installed automatically.
fix
Install Pillow:
pip install Pillow error pdf417gen.encode() got multiple values for argument 'columns' ↓
cause Passed both positional and keyword argument for columns, or incorrect signature.
fix
Use keyword arguments:
encode('data', columns=5) instead of positional. Warnings
gotcha The function `render_image` returns a PIL Image, not a file path. You must save it explicitly with `image.save('file.png')`. ↓
fix Call `image.save('output.png')` or use `render_image(codes).save('output.png')`.
gotcha Input must be a string, bytes, or an integer (single codeword). Passing a list of integers not as codewords will produce unexpected results. ↓
fix Pass a string (e.g., 'data') or bytes for binary data. Use `encode` which returns codewords.
gotcha In Python 3, the `encode` function expects a string by default. If you pass bytes, it tries to decode as utf-8; to encode raw bytes, convert to string appropriately. ↓
fix For binary data: `encode(data.decode('latin-1'))` or use `data` directly if it's a string.
Imports
- encode
from pdf417gen import encode - render_image
from pdf417gen import render_image - render_svg
from pdf417gen import render_svg - to_legacy_barcodes
from pdf417gen import to_legacy_barcodes
Quickstart
from pdf417gen import encode, render_image
from PIL import Image
# Encode a string into barcode codewords
codes = encode('Hello, PDF417!')
# Render as PIL Image (returns a PIL Image object)
image = render_image(codes) # type: Image.Image
image.save('barcode.png')