परिचय

Aspose.BarCode Python के लिए FOSS सात सिम्बोलॉजीज़ में बारकोड बनाता है और उन्हें SVG और PNG में रेंडर करता है। यह पोस्ट रेंडरिंग पाइपलाइन पर केंद्रित है — RenderOptions, SvgRenderer, और PngRenderer का उपयोग करके आउटपुट फ़ॉर्मेट, आयाम, रंग, और मानव-पठनीय टेक्स्ट को कैसे नियंत्रित किया जाए।

लाइब्रेरी PyPI पर aspose-barcode-foss के रूप में उपलब्ध है, जो MIT लाइसेंस के तहत जारी की गई है और इसमें कोई नेटिव डिपेंडेंसीज़ नहीं हैं। प्रत्येक बारकोड ऑब्जेक्ट to_svg() और to_png() सुविधा मेथड्स प्रदान करता है, साथ ही एक लोअर-लेवल render() मेथड भी है जो किसी भी Renderer इम्प्लीमेंटेशन को स्वीकार करता है।


मुख्य विशेषताएँ

SVG आउटपुट SvgRenderer के साथ

SvgRenderer रिज़ॉल्यूशन-इंडिपेंडेंट SVG मार्कअप उत्पन्न करता है। Barcode.to_svg() मेथड एक शॉर्टकट है जो आंतरिक रूप से SvgRenderer का उपयोग करता है।

from aspose_barcode_foss import BarcodeService, RenderOptions
from aspose_barcode_foss.rendering import SvgRenderer

service = BarcodeService()
barcode = service.generate("code128", "RENDER-TEST-001")

# Direct convenience method
svg_string = barcode.to_svg(RenderOptions(scale=2.0))

# Explicit renderer usage
renderer = SvgRenderer()
result = barcode.render(renderer, RenderOptions(scale=2.0, show_text=True))

PNG आउटपुट PngRenderer के साथ

PngRenderer रास्टर PNG छवियाँ बनाता है। RenderOptions पर dpi प्रॉपर्टी के साथ रिज़ॉल्यूशन नियंत्रित करें। Barcode.to_png() मेथड एक सुविधाजनक शॉर्टकट है।

from aspose_barcode_foss import BarcodeService, RenderOptions
from aspose_barcode_foss.rendering import PngRenderer

service = BarcodeService()
barcode = service.generate("ean13", "590123412345")

# Convenience method — returns bytes
png_bytes = barcode.to_png(RenderOptions(dpi=300, scale=3.0))

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

स्केल और DPI को नियंत्रित करना

RenderOptions scale (मॉड्यूल आयामों के गुणक) और dpi (रास्टर आउटपुट के लिए डॉट्स पर इंच) प्रदान करता है। ये साथ मिलकर काम करते हैं: scale बार और स्पेस के तर्कसंगत आकार को प्रभावित करता है, जबकि dpi PNG आउटपुट में पिक्सेल घनत्व को नियंत्रित करता है।

from aspose_barcode_foss import RenderOptions

# High-resolution print label
print_options = RenderOptions(scale=4.0, dpi=600)

# Screen display
screen_options = RenderOptions(scale=1.0, dpi=96)

रंग और पृष्ठभूमि

foreground_color और background_color को CSS रंग स्ट्रिंग्स के रूप में सेट करें। transparent_background को सक्षम करें ताकि पृष्ठभूमि भराव को छोड़ दिया जाए (मौजूदा डिज़ाइनों पर ओवरले करने के लिए उपयोगी)।

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()
barcode = service.generate("qrcode", "https://example.com")

options = RenderOptions(
    foreground_color="#003366",
    background_color="#FFFFFF",
    scale=3.0,
)
svg = barcode.to_svg(options)

क्वाइट ज़ोन नियंत्रण

quiet_zone प्रॉपर्टी बारकोड के आसपास ब्लैंक मार्जिन को मॉड्यूल-चौड़ाई इकाइयों में सेट करती है। अधिकांश बारकोड मानकों को विश्वसनीय स्कैनिंग के लिए न्यूनतम क्वाइट ज़ोन की आवश्यकता होती है।

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()
barcode = service.generate("code39", "QUIET-ZONE")

# Wider quiet zone for print use
options = RenderOptions(quiet_zone=10.0, scale=2.0)
svg = barcode.to_svg(options)

मानव-पठनीय पाठ

show_text=True को सेट करें ताकि बारकोड के नीचे एन्कोडेड डेटा दिखे। font_family और font_size प्रॉपर्टीज़ टेक्स्ट की उपस्थिति को नियंत्रित करती हैं।

from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()
barcode = service.generate("upca", "01234567890")

options = RenderOptions(
    show_text=True,
    font_family="monospace",
    font_size=12.0,
    scale=2.5,
)
svg = barcode.to_svg(options)

त्वरित शुरुआत

asposefoss/barcode is not yet published — build from source until it ships. See the project README for build instructions.
from aspose_barcode_foss import BarcodeService, RenderOptions

service = BarcodeService()

# Generate a Code 128 barcode
barcode = service.generate("code128", "HELLO-2026")

# Render to SVG with custom options
options = RenderOptions(
    scale=2.0,
    show_text=True,
    foreground_color="#000000",
    background_color="#FFFFFF",
    quiet_zone=4.0,
)

svg_output = barcode.to_svg(options)
with open("hello.svg", "w") as f:
    f.write(svg_output)

# Render to PNG at 300 DPI
png_bytes = barcode.to_png(RenderOptions(dpi=300, scale=3.0))
with open("hello.png", "wb") as f:
    f.write(png_bytes)

समर्थित प्रारूप

फ़ॉर्मेटएक्सटेंशनपढ़ेंलिखें
SVG.svg
PNG.png

ध्यान दें: PdfRenderer API में मौजूद है लेकिन वर्तमान रिलीज़ में NotImplementedError उत्पन्न करता है।


ओपन सोर्स और लाइसेंसिंग

Aspose.BarCode Python के लिए FOSS MIT लाइसेंस के तहत जारी किया गया है। स्रोत कोड GitHub पर होस्ट किया गया है। आप लाइब्रेरी को ओपन-सोर्स और व्यावसायिक दोनों प्रोजेक्ट्स में उपयोग, संशोधित और पुनर्वितरित कर सकते हैं।


शुरू करना

संबंधित संसाधन