Created
June 12, 2026 10:05
-
-
Save aspose-com-gists/aadcb87dc58f80b8a845fb196ba5475b to your computer and use it in GitHub Desktop.
Generate Code 39 Barcode in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Generate Code 39 Barcode in Python | |
| # Read the full guide here: https://blog.aspose.com/barcode/generate-code-39-barcode-in-python/ | |
| # Complete working example to generate a Code 39 barcode in Python | |
| import asposebarcode as barcode | |
| def generate_code39(text: str, output_path: str): | |
| # Initialize the barcode generator | |
| generator = barcode.BarCodeGenerator() | |
| # Set symbology to Code 39 (standard) | |
| generator.encode_type = barcode.EncodeTypes.CODE_39_STANDARD | |
| # Assign the text to encode (must be uppercase letters, digits, or - . $ / + % SPACE) | |
| generator.code_text = text.upper() | |
| # Optional appearance settings | |
| generator.x_dimension = 2 # Width of the narrow bar (pixels) | |
| generator.bar_height = 100 # Height of the barcode (pixels) | |
| generator.fore_color = barcode.Color.black | |
| generator.back_color = barcode.Color.white | |
| # Save the barcode as PNG | |
| generator.save(output_path, barcode.BarCodeImageFormat.PNG) | |
| if __name__ == "__main__": | |
| # Example usage | |
| generate_code39("ABC123", "code39_barcode.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment