Features and Functionalities
Features and Functionalities
Aspose.BarCode FOSS for Python provides a high-level API for generating seven barcode symbologies with per-symbology encode options and rendering controls. This page is the primary reference for all feature areas.
Supported Symbologies
The library supports seven symbologies through dedicated helper functions and the generic generate() entry point:
| Symbology | Type | Helper | Options Class |
|---|---|---|---|
| Code 128 | 1D | code128() | Code128Options |
| Code 39 | 1D | code39() | Code39Options |
| EAN-13 | 1D | ean13() | Ean13Options |
| EAN-8 | 1D | ean8() | Ean8Options |
| QR Code | 2D | qr() | QrOptions |
| UPC-A | 1D | upca() | UpcaOptions |
| UPC-E | 1D | upce() | UpceOptions |
import aspose_barcode_foss as barcode
# Per-symbology helpers
bc_128 = barcode.code128("ABC123")
bc_qr = barcode.qr("https://example.com")
# Generic API
bc_gen = barcode.generate("ean13", "590123412345")Code 128 Encode Modes
Code128Options controls which Code 128 character sets the encoder uses. The encode_mode property accepts a Code128EncodeMode enum value:
AUTO— selects the most compact encoding automaticallyCODE_A,CODE_B,CODE_C— restrict to a single character setCODE_AB,CODE_AC,CODE_BC— allow switching between two character sets
from aspose_barcode_foss import Code128Options, Code128EncodeMode
bc = barcode.code128(
"1234567890",
encode=Code128Options(encode_mode=Code128EncodeMode.CODE_C),
)Code 39 Encoding
Code39Options controls whether the encoder uses the base 43-character set or the Full ASCII extension:
full_ascii— set toTrueto encode the full 128-character ASCII range using shift pairsadd_check_digit— appends a modulo-43 check digit
from aspose_barcode_foss import Code39Options
bc = barcode.code39(
"Hello",
encode=Code39Options(full_ascii=True, add_check_digit=True),
)QR Code Configuration
QrOptions provides the most configuration among all symbologies:
| Property | Type | Values |
|---|---|---|
error_correction_level | QrErrorCorrectionLevel | L (7%), M (15%), Q (25%), H (30%) |
encoding_mode | QrEncodeMode | AUTO, NUMERIC, ALPHANUMERIC, BYTE, KANJI |
version | int | 1–40 (controls symbol size) |
mask | int | 0–7 (manual mask pattern selection) |
from aspose_barcode_foss import QrOptions, QrErrorCorrectionLevel, QrEncodeMode
bc = barcode.qr(
"https://example.com/product/12345",
encode=QrOptions(
error_correction_level=QrErrorCorrectionLevel.Q,
encoding_mode=QrEncodeMode.BYTE,
),
)EAN and UPC Check Digits
Ean13Options, Ean8Options, UpcaOptions, and UpceOptions each have an allow_check_digit_input property. By default, the library computes the check digit automatically. Set allow_check_digit_input=True if your data already includes it.
from aspose_barcode_foss import Ean13Options
# Automatic check digit (12 digits in, library appends the 13th)
bc = barcode.ean13("590123412345")
# Pre-computed check digit (13 digits, library validates)
bc2 = barcode.ean13(
"5901234123457",
encode=Ean13Options(allow_check_digit_input=True),
)Rendering Controls
RenderOptions applies to all symbologies and controls the visual output. Pass it to to_svg() or to_png():
| Property | Type | Description |
|---|---|---|
scale | float | Uniform scale multiplier |
dpi | int | Resolution for PNG output |
module_width | float | Width of one barcode module |
module_height | float | Height of one barcode module |
quiet_zone | float | Whitespace padding around the barcode |
foreground_color | str | Hex color for bars (e.g., "#000000") |
background_color | str | Hex color for background |
transparent_background | bool | Transparent background for PNG |
show_text | bool | Show human-readable text below barcode |
font_family | str | Font for human-readable text |
font_size | float | Font size for human-readable text |
from aspose_barcode_foss import RenderOptions
bc = barcode.upca("01234567890")
png = bc.to_png(options=RenderOptions(
scale=3.0,
dpi=300,
foreground_color="#1a1a1a",
background_color="#ffffff",
show_text=True,
))Output Formats
| Format | Method | Return Type |
|---|---|---|
| SVG | to_svg() | str |
| PNG | to_png() | bytes |
Both methods accept an optional RenderOptions parameter.
Error Handling
All encode option validation happens at parse time. The library raises typed exceptions before encoding begins:
| Exception | When Raised |
|---|---|
InvalidInputError | Data contains characters not supported by the symbology |
EncodingError | Encoding fails (e.g., data exceeds capacity) |
SymbologyNotFoundError | Unrecognized symbology name passed to generate() |
UnsupportedCapabilityError | Requested feature not available for this symbology |
All exception classes inherit from BarcodeError.
from aspose_barcode_foss import InvalidInputError
try:
bc = barcode.ean13("ABC")
except InvalidInputError as e:
print(f"Invalid input: {e}")Input Validation
Each symbology has a dedicated InputParser that validates data before encoding. The parser checks character set, length, and format requirements specific to each symbology. Code128InputParser, Code39InputParser, Ean13InputParser, Ean8InputParser, QrInputParser, UpcaInputParser, and UpceInputParser are used internally by their respective helper functions.
Barcode Object
The Barcode object returned by all helper functions provides:
to_svg(options)— render to SVG stringto_png(options)— render to PNG bytesrender(renderer, options)— render using a specificRendererimplementationsymbol— theEncodedSymbolcontaining the module matrix and metadataprofile— theSymbologyProfilewith defaults and capabilities
API Reference Summary
| Class | Description |
|---|---|
Barcode | Public barcode object with to_svg() and to_png() |
Code128Options | Encoding options for Code 128 (encode_mode) |
Code39Options | Encoding options for Code 39 (full_ascii, add_check_digit) |
QrOptions | Encoding options for QR Code (error_correction_level, encoding_mode, version, mask) |
Ean13Options | Encoding options for EAN-13 (allow_check_digit_input) |
Ean8Options | Encoding options for EAN-8 (allow_check_digit_input) |
UpcaOptions | Encoding options for UPC-A (allow_check_digit_input) |
UpceOptions | Encoding options for UPC-E (allow_check_digit_input, number_system) |
RenderOptions | Visual output controls (scale, DPI, colors, text) |
EncodeOptions | Base type for symbology-specific encoding options |
BarcodeError | Base exception for the barcode library |