Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/acc0c4fc9a62b980b6936d122fc2e52f to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/acc0c4fc9a62b980b6936d122fc2e52f to your computer and use it in GitHub Desktop.
Generate Swiss Barcode in Python
from aspose.barcode import generation
from aspose.pydrawing import Color
def generate_swiss_barcode(data, jpeg_path, pdf_path):
# Initialize generator with Swiss QR Code symbology
generator = generation.BarcodeGenerator(
generation.EncodeTypes.SWISS_POST_PARCEL,
data
)
# Size configuration
generator.parameters.barcode.x_dimension.pixels = 2.5 # points per module
generator.parameters.barcode.bar_height.pixels = 40
# generator.parameters.barcode.code_text_margin = 6
# Color customization
generator.parameters.barcode.bar_color = Color.from_argb(236, 100, 75, 1) # black
generator.parameters.back_color = Color.from_argb(255, 255, 255, 255) # white
# Export to JPEG
generator.save(jpeg_path, generation.BarCodeImageFormat.JPEG)
# Export to PDF (embedding)
generator.save(pdf_path, generation.BarCodeImageFormat.PDF)
if __name__ == "__main__":
try:
generate_swiss_barcode(
data="1234567890123456",
jpeg_path="output/swiss_barcode.jpg",
pdf_path="output/swiss_barcode.pdf"
)
print("Swiss barcode generated successfully.")
except Exception as e:
print(f"Error generating barcode: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment