עבודה עם אפשרויות Encode
עבודה עם אפשרויות Encode
כל סמל קוד שורת ב- Aspose.BarCode FOSS עבור Python יש כיתה אפשרויות מוקדשת שמשלבת התנהגות הקוד. EncodeOptions,אשר מספקת gs1_enabled ו eci_assignment_number תכונות משותפות בין סמלים.
Code128Options
Code128Options הקוד 128 מופיע בתכונה שבה קוד משתמש בוחרים. encode_mode רכוש מקבל A Code128EncodeMode ערך של Enum.
| Mode | Description |
|---|---|
AUTO | בחר את הקוד הכי קומפקטי באופן אוטומטי |
CODE_A | הגדרות, דיגיטליות ושל דמויות בקרה |
CODE_B | העליון, הנמוך והמספרים |
CODE_C | זוגות דיגיטליים – אופטימיזציה לנתונים מספרים בלבד |
CODE_AB | סתירה בין קוד A לבין קוד B |
CODE_AC | סתירה בין קוד A לבין קוד C |
CODE_BC | סתירה בין קוד B לבין קוד C |
import aspose_barcode_foss as barcode
from aspose_barcode_foss import Code128Options, Code128EncodeMode
# AUTO mode — library picks the most compact encoding
bc_auto = barcode.code128("ABC123", encode=Code128Options(encode_mode=Code128EncodeMode.AUTO))
# CODE_C mode — compact encoding for digit-only data
bc_c = barcode.code128("9876543210", encode=Code128Options(encode_mode=Code128EncodeMode.CODE_C))
# CODE_B mode — full alphanumeric support
bc_b = barcode.code128("Hello World", encode=Code128Options(encode_mode=Code128EncodeMode.CODE_B))Code39Options
Code39Options הוא בודק אם הקודר משתמש בסדרה בסיסית של 43 תווים או הרחבה ASCII מלאה.
| Property | Type | Default | Description |
|---|---|---|---|
full_ascii | bool | None | מאפשרת מצב ASCII מלא (128 טופס באמצעות זוגות החלפה) |
add_check_digit | bool | None | הוספת מודול 43 צ’ק דיגיטלי |
from aspose_barcode_foss import Code39Options
# Base mode — uppercase letters, digits, and a few special characters
bc_base = barcode.code39("CODE 39")
# Full ASCII mode — encodes the full 128-character ASCII range
bc_full = barcode.code39(
"Hello, World!",
encode=Code39Options(full_ascii=True, add_check_digit=True),
)QROptions
QrOptions יש את פני השטח המורכב ביותר בין כל הסמבלולוגיות.
| Property | Type | 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 (controls symbol dimensions) |
mask | int | 0–7 (manual mask pattern selection) |
from aspose_barcode_foss import QrOptions, QrErrorCorrectionLevel, QrEncodeMode
# High error correction with byte encoding
bc = barcode.qr(
"https://example.com",
encode=QrOptions(
error_correction_level=QrErrorCorrectionLevel.H,
encoding_mode=QrEncodeMode.BYTE,
),
)
# Numeric mode for digit-only data — most compact QR
bc_num = barcode.qr(
"0123456789",
encode=QrOptions(encoding_mode=QrEncodeMode.NUMERIC),
)
# Explicit version and mask
bc_v5 = barcode.qr(
"TEST",
encode=QrOptions(version=5, mask=3),
)Ean13Options
Ean13Options בקרת הפיקוח על ניהול דיגיטלי עבור קודים EAN-13.
| Property | Type | Default | Description |
|---|---|---|---|
allow_check_digit_input | bool | None | קבל כניסה 13 דיגיטלית עם מדד הבדיקה המוקדם מחשב |
from aspose_barcode_foss import Ean13Options
# 12 digits — library computes the 13th check digit
bc = barcode.ean13("590123412345")
# 13 digits — library validates the provided check digit
bc2 = barcode.ean13(
"5901234123457",
encode=Ean13Options(allow_check_digit_input=True),
)Ean8Options
Ean8Options עובד באופן זהה ל Ean13Options אבל עבור קודים EAN 8 דיגיטליים. לספק 7 דיגרים של משאבים (הספרייה מחושבת את השמיני), או להגדיר allow_check_digit_input=True כניסה 8 דיגיטליות.
from aspose_barcode_foss import Ean8Options
bc = barcode.ean8("1234567")
bc2 = barcode.ean8("12345670", encode=Ean8Options(allow_check_digit_input=True))UpcaOptions ו-UpceOption
UpcaOptions ו UpceOptions עקבו אחרי אותו דבר allow_check_digit_input אפשרויות כגון EAN. UpceOptions יש גם A number_system רכוש .
from aspose_barcode_foss import UpcaOptions, UpceOptions
# UPC-A: 11 digits, library adds check digit
bc_a = barcode.upca("01234567890")
# UPC-E with pre-computed check digit
bc_e = barcode.upce(
"01234565",
encode=UpceOptions(allow_check_digit_input=True),
)אופי בסיס של EncodeOptions
כל התכונות האופציונליות מורשת את המאפיינים הללו מ- EncodeOptions:
| Property | Type | Description |
|---|---|---|
gs1_enabled | `bool | None` |
eci_assignment_number | `int | None` |
טיפים ושיטות טובות
- שימוש
Code128EncodeMode.AUTOאלא אם כן יש לך סיבה ספציפית להגביל את קבוצות הדמויות - זה מייצר את הקוד הבר הקצר ביותר עבור כל כניסה. - סדנה
QrErrorCorrectionLevel.Hעבור קוד QR אשר יידפס על פני השטח פוטנציאלי לנזק. - תן לספריה לחשב לבדוק את המספרים כברירת מחדל - רק הגדרת
allow_check_digit_input=Trueכאשר מקבלים נתונים מאושרים מראש ממערכת אחרת. - שימוש
QrEncodeMode.NUMERICכדי להגדיר את הנתונים QR בלבד כדי למזער את גודל הסימולטור.
בעיות נפוצות
| Issue | Cause | קבע |
|---|---|---|
InvalidInputError על קוד 39 | תגיות קשורות מכתבים נמוכים | סדנה full_ascii=True בתוך Code39Options |
| קוד QR גדול מדי | הגדרה נמוכה מדי עבור אורך הנתונים | להסיר באופן ברור version או להגדיל את זה |
| בדוק את המספר הלא נכון ב- EAN-13 | 13-digit input without allow_check_digit_input=True | עבר 12 ציונים (אוטומטי) או הגדר את האפשרות ל True |
SymbologyNotFoundError | שם סימבוליזם שגוי generate() | השתמשו באחד מהם: code128, code39, ean13, ean8, qr, upca, upce |