กรณีการใช้งานการสร้างบาร์โค้ด
Aspose.BarCode FOSS สำหรับ Python รองรับสัญลักษณ์เจ็ดแบบ: 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().
รูปแบบผลลัพธ์ที่มีให้ใช้งานมีอะไรบ้าง?
ไลบรารีทำการเรนเดอร์เป็น SVG ผ่าน to_svg() และ PNG ผ่าน to_png(). การเรนเดอร์ PDF ยังไม่ได้ทำงาน.