バーコード生成のユースケース

バーコード生成のユースケース

Aspose.BarCode FOSS for Python は、7つのシンボルをサポートしています: Code 128、Code 39、EAN-13、EAN-8、QR Code、UPC-A、および UPC-E。この記事ではそれぞれの実用的なシナリオを示します。

在庫管理

Code 128 は、英数字データと特殊文字をエンコードできるため、在庫ラベルの一般的な選択肢です。各アイテムにはラベルに印刷されたユニークな識別子が付与されます。

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()

# Generate a Code 128 barcode for an inventory SKU
barcode = service.generate("code128", "SKU-2026-A1234")
svg_content = barcode.to_svg(RenderOptions(scale=2.0, show_text=True))

with open("inventory_label.svg", "w") as f:
    f.write(svg_content)

出荷ラベル

Code 128 と Code 39 は、出荷および物流で広く使用されています。Code 39 はよりシンプルで(大文字、数字、いくつかの記号)古いシステムで使用されます。Code 128 はより広い文字セットをサポートしています。

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()

# Code 39 for a tracking number
barcode = service.generate("code39", "SHIP2026071234")
png_bytes = barcode.to_png(RenderOptions(dpi=300, show_text=True))

with open("shipping_label.png", "wb") as f:
    f.write(png_bytes)

小売販売時点

EAN-13 と UPC-A は小売製品の標準シンボルです。EAN-13 は国際的に使用され、UPC-A は12桁の北米向けバリアントです。

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()

# EAN-13 for a product barcode (12 digits; check digit auto-computed)
barcode = service.generate("ean13", "590123412345")
svg_content = barcode.to_svg(RenderOptions(scale=3.0, show_text=True))

# UPC-A for a North American product
barcode_upc = service.generate("upca", "01234567890")
svg_upc = barcode_upc.to_svg(RenderOptions(scale=3.0, show_text=True))

文書追跡

Code 128は、各文書が一意の英数字識別子を受け取る文書追跡システムに適しています。

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()

# Generate barcodes for a batch of documents
doc_ids = ["DOC-2026-001", "DOC-2026-002", "DOC-2026-003"]
for doc_id in doc_ids:
    barcode = service.generate("code128", doc_id)
    svg = barcode.to_svg(RenderOptions(scale=1.5, show_text=True))
    filename = f"{doc_id.lower().replace('-', '_')}.svg"
    with open(filename, "w") as f:
        f.write(svg)

URL と 連絡先のエンコード(QR コード)

QR Codeは、URL、連絡先情報、Wi-Fi 認証情報などの任意のテキストデータをエンコードします。

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()

# QR Code for a URL
barcode = service.generate("qrcode", "https://products.aspose.org/barcode/")
png_bytes = barcode.to_png(RenderOptions(scale=4.0))

with open("url_qrcode.png", "wb") as f:
    f.write(png_bytes)

小型アイテムラベル(EAN-8 と UPC-E)

EAN-8 と UPC-E は、スペースが限られたアイテム向けのコンパクトなシンボロジーです。EAN-8 は 7 桁または 8 桁を使用します;UPC-E は UPC-A の圧縮バージョンです。

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()

# EAN-8 for a small product (7 digits; check digit auto-computed)
barcode = service.generate("ean8", "1234567")
svg = barcode.to_svg(RenderOptions(scale=2.0, show_text=True))

よくある質問

どのシンボロジーを選べばよいですか?

  • 英数字データ(任意の文字): Code 128
  • 大文字のみ、レガシーシステム: Code 39
  • 小売製品(国際): EAN-13 または EAN-8
  • 小売製品(北米): UPC-A または UPC-E
  • URL、テキスト、バイナリデータ: QR Code

バーコードをバッチで生成できますか?

はい。一度BarcodeServiceインスタンスを作成し、ループ内でgenerate()を呼び出します。各呼び出しはBarcodeオブジェクトを返し、to_svg()またはto_png()で個別にレンダリングできます。

利用可能な出力フォーマットは何ですか?

このライブラリは to_svg() を使用して SVG に、to_png() を使用して PNG にレンダリングします。PDF のレンダリングはまだ実装されていません。

参照

 日本語