Features and Functionalities

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:

SymbologyTypeHelperOptions Class
Code 1281Dcode128()Code128Options
Code 391Dcode39()Code39Options
EAN-131Dean13()Ean13Options
EAN-81Dean8()Ean8Options
QR Code2Dqr()QrOptions
UPC-A1Dupca()UpcaOptions
UPC-E1Dupce()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 automatically
  • CODE_A, CODE_B, CODE_C — restrict to a single character set
  • CODE_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 to True to encode the full 128-character ASCII range using shift pairs
  • add_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:

PropertyTypeValues
error_correction_levelQrErrorCorrectionLevelL (7%), M (15%), Q (25%), H (30%)
encoding_modeQrEncodeModeAUTO, NUMERIC, ALPHANUMERIC, BYTE, KANJI
versionint1–40 (controls symbol size)
maskint0–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():

PropertyTypeDescription
scalefloatUniform scale multiplier
dpiintResolution for PNG output
module_widthfloatWidth of one barcode module
module_heightfloatHeight of one barcode module
quiet_zonefloatWhitespace padding around the barcode
foreground_colorstrHex color for bars (e.g., "#000000")
background_colorstrHex color for background
transparent_backgroundboolTransparent background for PNG
show_textboolShow human-readable text below barcode
font_familystrFont for human-readable text
font_sizefloatFont 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

FormatMethodReturn Type
SVGto_svg()str
PNGto_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:

ExceptionWhen Raised
InvalidInputErrorData contains characters not supported by the symbology
EncodingErrorEncoding fails (e.g., data exceeds capacity)
SymbologyNotFoundErrorUnrecognized symbology name passed to generate()
UnsupportedCapabilityErrorRequested 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 string
  • to_png(options) — render to PNG bytes
  • render(renderer, options) — render using a specific Renderer implementation
  • symbol — the EncodedSymbol containing the module matrix and metadata
  • profile — the SymbologyProfile with defaults and capabilities

API Reference Summary

ClassDescription
BarcodePublic barcode object with to_svg() and to_png()
Code128OptionsEncoding options for Code 128 (encode_mode)
Code39OptionsEncoding options for Code 39 (full_ascii, add_check_digit)
QrOptionsEncoding options for QR Code (error_correction_level, encoding_mode, version, mask)
Ean13OptionsEncoding options for EAN-13 (allow_check_digit_input)
Ean8OptionsEncoding options for EAN-8 (allow_check_digit_input)
UpcaOptionsEncoding options for UPC-A (allow_check_digit_input)
UpceOptionsEncoding options for UPC-E (allow_check_digit_input, number_system)
RenderOptionsVisual output controls (scale, DPI, colors, text)
EncodeOptionsBase type for symbology-specific encoding options
BarcodeErrorBase exception for the barcode library

See Also

 English