機能と特徴
機能と特長
Aspose.BarCode FOSS for Python は、7 つのバーコードシンボロジーを生成するための高レベルな API を提供し、シンボロジーごとのエンコードオプションとレンダリングコントロールが可能です。このページは、すべての機能領域に関する主要なリファレンスです。
サポートされているシンボロジー
このライブラリは、専用のヘルパー関数と汎用の generate() エントリーポイントを通じて、7 つのシンボロジーをサポートします:
| Symbology | 型 | Helper | Options クラス |
|---|---|---|---|
| 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 エンコードモード
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_level | QrErrorCorrectionLevel | L (7%), M (15%), Q (25%), H (30%) |
encoding_mode | QrEncodeMode | AUTO, NUMERIC, ALPHANUMERIC, BYTE, KANJI |
version | int | 1–40 (シンボルサイズを制御) |
mask | int | 0–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() に渡してください:
| プロパティ | 型 | 説明 |
|---|---|---|
scale | float | 均一スケール乗数 |
dpi | int | PNG 出力の解像度 |
module_width | float | 1つのバーコードモジュールの幅 |
module_height | float | 1つのバーコードモジュールの高さ |
quiet_zone | float | バーコード周囲の余白パディング |
foreground_color | str | バーの16進カラー(例: "#000000") |
background_color | str | 背景の16進カラー |
transparent_background | bool | PNG の透過背景 |
show_text | bool | バーコードの下に人が読めるテキストを表示する |
font_family | str | 人が読めるテキストのフォント |
font_size | float | 人が読めるテキストのフォントサイズ |
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,
))出力形式
| フォーマット | メソッド | 戻り値の型 |
|---|---|---|
| SVG | to_svg() | str |
| PNG | to_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()) |
Code128Options | Code 128 のエンコーディングオプション(encode_mode) |
Code39Options | Code 39 のエンコーディングオプション(full_ascii、add_check_digit) |
QrOptions | QR Code のエンコーディングオプション(error_correction_level、encoding_mode、version、mask) |
Ean13Options | EAN-13 のエンコーディング オプション (allow_check_digit_input) |
Ean8Options | EAN-8 のエンコーディング オプション (allow_check_digit_input) |
UpcaOptions | UPC-A のエンコーディング オプション (allow_check_digit_input) |
UpceOptions | UPC-E のエンコーディング オプション (allow_check_digit_input, number_system) |
RenderOptions | ビジュアル出力コントロール(スケール、DPI、カラー、テキスト) |
EncodeOptions | シンボロジー固有エンコードオプションのベースタイプ |
BarcodeError | バーコードライブラリ用ベース例外 |