機能と特徴

機能と特長

Aspose.BarCode FOSS for Python は、7 つのバーコードシンボロジーを生成するための高レベルな API を提供し、シンボロジーごとのエンコードオプションとレンダリングコントロールが可能です。このページは、すべての機能領域に関する主要なリファレンスです。


サポートされているシンボロジー

このライブラリは、専用のヘルパー関数と汎用の generate() エントリーポイントを通じて、7 つのシンボロジーをサポートします:

Symbology型HelperOptions クラス
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 エンコードモード

Code128Options は、エンコーダが使用する Code 128 の文字セットを制御します。encode_mode プロパティは Code128EncodeMode 列挙型の値を受け取ります:

  • AUTO — 最もコンパクトなエンコードを自動的に選択します
  • CODE_A、CODE_B、CODE_C — 単一の文字セットに制限する
  • CODE_AB、CODE_AC、CODE_BC — 2つの文字セット間の切り替えを許可する
from aspose_barcode_foss import Code128Options, Code128EncodeMode

bc = barcode.code128(
    "1234567890",
    encode=Code128Options(encode_mode=Code128EncodeMode.CODE_C),
)

Code 39 エンコーディング

Code39Options は、エンコーダが基本の43文字セットを使用するか、Full ASCII 拡張を使用するかを制御します:

  • full_ascii — True に設定すると、シフトペアを使用して128文字のASCII全範囲をエンコードします
  • add_check_digit — modulo-43 のチェックデジットを付加します
from aspose_barcode_foss import Code39Options

bc = barcode.code39(
    "Hello",
    encode=Code39Options(full_ascii=True, add_check_digit=True),
)

QR Code 設定

QrOptions は、すべてのシンボロジーの中で最も多くの設定を提供します:

プロパティ型Values
error_correction_levelQrErrorCorrectionLevelL (7%), M (15%), Q (25%), H (30%)
encoding_modeQrEncodeModeAUTO, NUMERIC, ALPHANUMERIC, BYTE, KANJI
versionint1–40 (シンボルサイズを制御)
maskint0–7(手動マスクパターン選択)
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 と UPC のチェックディジット

Ean13Options、Ean8Options、UpcaOptions、および UpceOptions はそれぞれ allow_check_digit_input プロパティを持ちます。デフォルトでは、ライブラリがチェックデジットを自動的に計算します。データにすでにチェックデジットが含まれている場合は allow_check_digit_input=True を設定してください。

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),
)

レンダリング制御

RenderOptions はすべてのシンボロジーに適用され、ビジュアル出力を制御します。to_svg() または to_png() に渡してください:

プロパティ型説明
scalefloat均一スケール乗数
dpiintPNG 出力の解像度
module_widthfloat1つのバーコードモジュールの幅
module_heightfloat1つのバーコードモジュールの高さ
quiet_zonefloatバーコード周囲の余白パディング
foreground_colorstrバーの16進カラー(例: "#000000")
background_colorstr背景の16進カラー
transparent_backgroundboolPNG の透過背景
show_textboolバーコードの下に人が読めるテキストを表示する
font_familystr人が読めるテキストのフォント
font_sizefloat人が読めるテキストのフォントサイズ
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,
))

出力形式

フォーマットメソッド戻り値の型
SVGto_svg()str
PNGto_png()bytes

両方のメソッドはオプションの RenderOptions パラメータを受け入れます。


エラー処理

すべてのエンコードオプションの検証はパース時に行われます。ライブラリはエンコードが開始される前に型付き例外をスローします:

Exception発生時
InvalidInputErrorデータにシンボロジーでサポートされていない文字が含まれています
EncodingErrorエンコードに失敗しました(例:データが容量を超えています)
SymbologyNotFoundError認識できないシンボロジー名が generate() に渡されました
UnsupportedCapabilityError要求された機能はこのシンボロジーでは利用できません

すべての例外クラスは BarcodeError を継承します。

from aspose_barcode_foss import InvalidInputError

try:
    bc = barcode.ean13("ABC")
except InvalidInputError as e:
    print(f"Invalid input: {e}")

入力検証

各シンボロジーにはエンコード前にデータを検証する専用の InputParser が用意されています。パーサは各シンボロジー固有の文字セット、長さ、フォーマット要件をチェックします。Code128InputParser、Code39InputParser、Ean13InputParser、Ean8InputParser、QrInputParser、UpcaInputParser、および UpceInputParser は、それぞれのヘルパー関数内部で使用されます。


バーコードオブジェクト

すべてのヘルパー関数が返す Barcode オブジェクトは、以下を提供します:

  • to_svg(options) — SVG文字列としてレンダリング
  • to_png(options) — PNGバイトとしてレンダリング
  • render(renderer, options) — 特定の Renderer 実装を使用してレンダリング
  • symbol — EncodedSymbol(モジュールマトリックスとメタデータを含む)
  • profile — デフォルトと機能を備えたSymbologyProfile

API Reference 概要

クラス説明
Barcodeパブリックバーコードオブジェクト(to_svg() と to_png())
Code128OptionsCode 128 のエンコーディングオプション(encode_mode)
Code39OptionsCode 39 のエンコーディングオプション(full_ascii、add_check_digit)
QrOptionsQR Code のエンコーディングオプション(error_correction_level、encoding_mode、version、mask)
Ean13OptionsEAN-13 のエンコーディング オプション (allow_check_digit_input)
Ean8OptionsEAN-8 のエンコーディング オプション (allow_check_digit_input)
UpcaOptionsUPC-A のエンコーディング オプション (allow_check_digit_input)
UpceOptionsUPC-E のエンコーディング オプション (allow_check_digit_input, number_system)
RenderOptionsビジュアル出力コントロール(スケール、DPI、カラー、テキスト)
EncodeOptionsシンボロジー固有エンコードオプションのベースタイプ
BarcodeErrorバーコードライブラリ用ベース例外

参照

 日本語