Borrow Aspose.BarCode barcode control to generate Code 128 barcode in Python

Barcoding is an integral part of today's businesses, from inventory management to retail transactions. Code 128 is one of the most versatile and widely used barcodes. Code 128 barcodes provide a practical solution for labeling products, tracking assets and improving operational efficiency. In this blog post, we will learn how to use the Aspose.Barcode barcode control to develop a 128 barcode generator in Python.

Aspose.BarCode for .NET  is a powerful API that can generate and recognize 1D and 2D barcodes in multiple image types from any angle. Developers can easily add barcode generation and recognition capabilities, as well as export generated barcodes to high-quality image formats in .NET applications. Aspose API supports popular file format processing and allows export or conversion of various types of documents to fixed layout file formats and the most commonly used image/multimedia formats.

Aspose.BarCode latest download (qun: 761297826) icon-default.png?t=N7T8https://www.evget.com/product/576/download

This article covers the following topics:

  • Python Code 128 Barcode Generator API
  • Generate Code 128 barcodes in Python
  • Generate GS1-128 barcode
  • UPC-A GS1 128 Coupon in Python
  • Customize barcode appearance

Code 128 barcode generator in Python.

Python Code 128 Barcode Generator API

We will use Aspose.BarCode for Python  to generate 128 barcodes. It is a powerful, reliable and user-friendly barcode generation and recognition solution. It supports multiple 1D and 2D barcode types.

Please use the following pip command in the console to download the package or install the API from PyPI:

pip install aspose-barcode-for-python-via-net
Generate Code 128 barcodes in Python

We can easily generate Code 128 barcode by following these steps:

  1. Create an instance of the BarcodeGenerator class using EncodeTypes.CODE128 as parameter .
  2. After that, specify the text to be encoded.
  3. Finally, save the output using the save() method. It takes the output file path as argument.

The following code example demonstrates how to generate a Code 128 barcode in Python .

# This code example demonstartes how to generate a Code 128 barcode.
import aspose.barcode as barcode

# Initialize the BarcodeGenerator
# Specify Encode type
generator = barcode.generation.BarcodeGenerator(barcode.generation.EncodeTypes.CODE128)

# Code text
generator.code_text = "123456ABCDEF"

# Save the generated barcode
generator.save("C:\\Files\\Generate_Code_128.jpg")

Generate GS1-128 barcode using Python

Generate GS1-128 barcodes in Python

We can easily generate GS1-128 barcode by following the steps below:

  1. Create an instance of the BarcodeGenerator class using EncodeTypes.GS1_CODE_128 as parameter .
  2. Specifies the text to encode.
  3. After that, set the barcode size value in pixels.
  4. Finally, save the output using the save() method. It takes the output file path as argument.

The following code example demonstrates how to generate a GS1-128 barcode in Python .

# This code example demonstartes how to generate a GS1 128 barcode.
import aspose.barcode as barcode

# Initialize the BarcodeGenerator
# Specify Encode type as GS1_CODE_128
generator = barcode.generation.BarcodeGenerator(barcode.generation.EncodeTypes.GS1_CODE_128)

# Code text
generator.code_text = "(01)12345678901231(21)ASPOSE(30)9876"

# Save the generated barcode
generator.save("C:\\Files\\GS1_128.jpg")

Generate GS1-128 barcode using Python

Generate UPC-A GS1 128 coupons in Python

We can also follow the previously mentioned steps to generate a barcode label where an additional GS1-128 coupon barcode is placed in the same image. However, we need to set EncodeTypes to UPCA_GS_1_CODE_128_COUPON in the first step .

The following code example demonstrates how to generate a UPC-A GS1 Code 128 coupon in Python .

# This code example demonstartes how to generate a GS1 128 Coupon barcode.
import aspose.barcode as barcode

# Initialize the BarcodeGenerator
# Specify Encode type
generator = barcode.generation.BarcodeGenerator(barcode.generation.EncodeTypes.UPCA_GS_1_CODE_128_COUPON)

# Code text
generator.code_text = "123456789012(8110)ASPOSE"

# Save the generated barcode
generator.save("C:\\Files\\GS1_128_COUPON.jpg")

Generate UPC-A GS1 128 coupons in Python

Customize the appearance of Code 128 coupons using Python

We can also customize the appearance of the barcode by following the steps mentioned earlier. However, before saving the image in the final step, we need to specify additional properties.

The following code example demonstrates how to customize the barcode appearance of the GS1 128 Coupon in Python .

# This code example demonstartes how to customize the appearance of a GS1 128 Coupon barcode.
import aspose.barcode as barcode
from aspose.pydrawing import Color, FontStyle

# Initialize the BarcodeGenerator
# Specify Encode type
generator = barcode.generation.BarcodeGenerator(barcode.generation.EncodeTypes.UPCA_GS_1_CODE_128_COUPON)

# Code text
generator.code_text = "123456789012(8110)ASPOSE"

# Customize caption above
generator.parameters.caption_above.text ="CAPTION ABOVE"
generator.parameters.caption_above.visible = True
generator.parameters.caption_above.font.style = FontStyle.ITALIC
generator.parameters.caption_above.font.size.point = 5.0

# Customize caption below
generator.parameters.caption_below.text = "CAPTION BELOW"
generator.parameters.caption_below.visible = True
generator.parameters.caption_below.font.style = FontStyle.BOLD
generator.parameters.caption_below.font.size.pixels = 15.0
generator.parameters.caption_above.font.family_name = "Verdana"

# Customize bar color
bar_color = Color(0x00, 0x00, 0xFF)
generator.parameters.barcode.bar_color = bar_color

# Specify the X-dimension
# the smallest width of the unit of BarCode bars or spaces
generator.parameters.barcode.x_dimension.pixels = 2.0;

# Set coupon supplement space 50 pixels
generator.parameters.barcode.coupon.supplement_space.pixels = 50.0;

# Set bar height
generator.parameters.barcode.bar_height.pixels = 50.0;

# Save the generated barcode
generator.save("C:\\Files\\Customize_Code_128.jpg")

Custom colors and coupon supplementary space in Python

The above is how to generate Code 128 barcode in Python with the help of Aspose.BarCode. I hope it can help you. In addition, if you have other needs, you are welcome to interact with us or experience it~

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/133020608