借Aspose.BarCode条码控件,在Python 中生成 Code 128 条形码

条形码是当今企业不可或缺的一部分,从库存管理到零售交易。Code 128 是最通用、使用最广泛的条形码之一。Code 128 条形码为标记产品、跟踪资产和提高运营效率提供了实用的解决方案。在这篇博文中,我们将学习如何使用 Aspose.Barcode条码控件,在Python 开发 128 条码生成器。

Aspose.BarCode for .NET 是一个功能强大的API,可以从任意角度生成和识别多种图像类型的一维和二维条形码。开发人员可以轻松添加条形码生成和识别功能,以及在.NET应用程序中将生成的条形码导出为高质量的图像格式。 Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

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

本文涵盖以下主题:

  • Python Code 128 条形码生成器 API
  • 在 Python 中生成 Code 128 条形码
  • 生成 GS1-128 条形码
  • Python 中的 UPC-A GS1 128 优惠券
  • 自定义条形码外观

Python 中的 Code 128 条形码生成器。

Python Code 128 条形码生成器 API

我们将使用Aspose.BarCode for Python 生成 128 个条形码。它是一个强大、可靠且用户友好的条形码生成和识别解决方案。它支持多种一维和二维条码类型。

请在控制台中使用以下 pip 命令从PyPI下载软件包或安装 API :

pip install aspose-barcode-for-python-via-net
在 Python 中生成 Code 128 条形码

我们可以按照以下步骤轻松生成 Code 128 条形码:

  1. 使用EncodeTypes.CODE128作为参数创建BarcodeGenerator类的实例。
  2. 之后,指定要编码的文本。
  3. 最后,使用save()方法保存输出。它将输出文件路径作为参数。

以下代码示例演示如何在 Python 中生成代码 128 条形码

# 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")

使用 Python 生成 GS1-128 条形码

在 Python 中生成 GS1-128 条形码

我们可以按照以下步骤轻松生成 GS1-128 条形码:

  1. 使用EncodeTypes.GS1_CODE_128作为参数创建BarcodeGenerator类的实例。
  2. 指定要编码的文本。
  3. 之后,设置条形码大小值(以像素为单位)。
  4. 最后,使用save()方法保存输出。它将输出文件路径作为参数。

以下代码示例演示如何在 Python 中生成 GS1-128 条形码

# 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")

使用 Python 生成 GS1-128 条形码

在 Python 中生成 UPC-A GS1 128 优惠券

我们还可以按照前面提到的步骤生成一个条形码标签,其中在同一图像中放置一个额外的 GS1-128 优惠券条形码。但是,我们需要在第一步中将EncodeTypes设置为UPCA_GS_1_CODE_128_COUPON 。

以下代码示例演示如何在 Python 中生成 UPC-A GS1 Code 128 优惠券

# 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")

在 Python 中生成 UPC-A GS1 128 优惠券

使用 Python 自定义 Code 128 优惠券外观

我们还可以按照前面提到的步骤自定义条形码的外观。但是,在最后一步中保存图像之前,我们需要指定其他属性。

以下代码示例演示如何在 Python 中自定义 GS1 128 Coupon 的条形码外观

# 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")

Python中自定义颜色和优惠券补充空间

以上便是如何借助Aspose.BarCode,在Python 中生成 Code 128 条形码,希望能帮到您,除此之外,你有其他方面的需求,也欢迎和我们互动,或这下体验~

猜你喜欢

转载自blog.csdn.net/m0_67129275/article/details/133020608