Barcode Generation Sử dụng trường hợp

Barcode Generation Sử dụng trường hợp

Aspose.BarCode FOSS for Python (pip install aspose-barcode-foss) hỗ trợ bảy biểu tượng: Mã 128, Mục 39, EAN-13, Ean-8, QR Code, UPC-A và U PC-E. Bài viết này cho thấy các kịch bản thực tế cho mỗi.

Quản lý inventory

Mã 128 là một lựa chọn phổ biến cho các nhãn lưu trữ bởi vì nó mã hóa dữ liệu alphanumeric bao gồm các ký tự đặc biệt. mỗi mục nhận được một ID độc đáo in trên một nhánh.

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)

Shipyard Nhãn hiệu

Mã 128 và mã 39 được sử dụng rộng rãi trong vận chuyển và logistics.Mã 39 đơn giản hơn (các lá thư, số, và một vài biểu tượng) và được dùng trong các hệ thống cũ hơn.

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)


---

## Điểm bán lẻ

EAN-13 và UPC-A là biểu tượng tiêu chuẩn cho các sản phẩm bán lẻ. Ean-13 được sử dụng quốc tế; U PC- A là biến thể Bắc Mỹ 12 chữ số.

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

Tài liệu theo dõi

Code 128 hoạt động tốt cho các hệ thống theo dõi tài liệu nơi mỗi tài khoản nhận được một bộ định danh alphanumeric độc đáo.

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 và liên hệ mã hóa với QR Codes

QR Code mã hóa dữ liệu văn bản tự nguyện bao gồm URL, thông tin liên hệ và tín hiệu Wi-Fi.

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)

Nhãn hiệu nhỏ với EAN-8 và UPC-E

EAN-8 và UPC-E là biểu tượng nhỏ gọn cho các mục nơi không gian hạn chế. Ean-8 sử dụng 7 hoặc 8 chữ số; U PC-e là một phiên bản nén của UCC-A.

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


## Thường xuyên hỏi câu hỏi

### Tôi nên chọn biểu tượng nào?

- **Dữ liệu Alfanumeric (mọi ký tự):** Mã 128
- **+ Hệ thống thừa kế:** Mã 39
- **Sản phẩm bán lẻ (tương quốc):** EAN-13 hoặc Ean-8
- **Sản phẩm bán lẻ (North America):** UPC-A hoặc UDC-E
- **URL, văn bản và dữ liệu nhị phân:** Mã QR

### Tôi có thể tạo mã thanh trong gói không?

Tạo a `BarcodeService` Lần 1 và gọi `generate()` Mỗi cuộc gọi sẽ trở lại một `Barcode` đối tượng mà bạn có thể tự do thực hiện với `to_svg()` hoặc `to_png()`.

### Các định dạng xuất khẩu nào có sẵn?

Thư viện chuyển giao cho SVG qua `to_svg()` PNG qua `to_png()`. PDF rendering chưa được thực hiện.

## See Also

- [Làm thế nào để làm việc với các tùy chọn Encode](https://kb.aspose.org/barcode/python/how-to-work-with-encode-options-python/)
- [Troubleshooting](https://kb.aspose.org/barcode/python/troubleshooting/)
- [Hướng dẫn dành cho nhà phát triển](https://docs.aspose.org/barcode/python/developer-guide/)
- [API tham khảo](https://reference.aspose.org/barcode/python/)
 Tiếng Việt