条码控件Aspose.BarCode入门教程(7):如何在Java 中的 GS1-128 条码生成器

Aspose.BarCode for .NET 是一个功能强大的API,可以从任意角度生成和识别多种图像类型的一维和二维条形码。开发人员可以轻松添加条形码生成和识别功能,以及在.NET应用程序中将生成的条形码导出为高质量的图像格式。

Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

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

条形码是用于识别产品的图形符号。在零售行业,GS1-128 条码无处不在。世界各地的许多公司都使用 GS1-128 标准交换数据。作为电子商务标准,它使公司能够提供有关其产品的准确可靠的信息。在本文中,我们将学习如何生成 GS1-128 条形码。完成上述步骤后,我们将拥有自己的Java GS1-128 条码生成器。让我们开始吧。

(一)安装Java GS1-128 条码生成器 API

我们将使用Aspose.BarCode for Java API 生成 GS1-128 条码。它是用于条形码生成和识别的强大、可靠且易于使用的 Java API。它支持范围广泛的一维和二维条码类型。

请下载 API 的 JAR或在基于 Maven 的 Java 应用程序中添加以下 pom.xml 配置。

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-barcode</artifactId>
    <version>22.10</version>
</dependency>

(二)在 Java 中生成 GS1-128 条码

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

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

以下代码示例显示了如何在 Java 中生成 GS1-128 条形码

// This code example demonstrates how to generate a GS1-128 barcode.
// Create an instane of the BarcodeGenerator class
// Specify Encode type as GS1Code128
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.GS_1_CODE_128);

// Specify the code text
generator.setCodeText("(01)12345678901231(21)ASPOSE(30)9876");

// Specify the X-dimension
// the smallest width of the unit of BarCode bars or spaces
generator.getParameters().getBarcode().getXDimension().setPixels(2);

// Save the output
generator.save("C:\\Files\\GS1Code128.jpg");

(三)在 Java 中生成 UPC-A GS1 128 优惠券

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

以下代码示例显示如何在 Java 中生成 UPC-A GS1 代码 128 优惠券。

// This code example demonstrates how to generate a UPC-A GS1 Code 128 Coupon.
// Create an instane of the BarcodeGenerator class
// Specify Encode type as UpcaGs1Code128Coupon
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.UPCA_GS_1_CODE_128_COUPON);

// Specify the code text
generator.setCodeText("123456789012(8110)ASPOSE");

// Specify the X-dimension
// the smallest width of the unit of BarCode bars or spaces
generator.getParameters().getBarcode().getXDimension().setPixels(2);

// Save the output
generator.save("C:\\Files\\Gs1CouponUpcaCode128.jpg");

(四)在 Java 中自定义 GS1 128 优惠券外观

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

下面的代码示例显示了如何在 Java 中自定义 GS1 128 优惠券的条形码外观。

// This code example demonstrates how to customize the barcode appearance of GS1 128 Coupon.
// Create an instane of the BarcodeGenerator class
// Specify Encode type as UpcaGs1Code128Coupon
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.UPCA_GS_1_CODE_128_COUPON);

// Specify the code text
generator.setCodeText("123456789012(8110)ASPOSE");

// Specify the X-dimension 
// the smallest width of the unit of BarCode bars or spaces
generator.getParameters().getBarcode().getXDimension().setPixels(2);

// Set coupon supplement space 50 pixels
generator.getParameters().getBarcode().getCoupon().getSupplementSpace().setPixels(50);

// Set Bar Height
generator.getParameters().getBarcode().getBarHeight().setPixels(50);

// Set Bar Color
generator.getParameters().getBarcode().setBarColor(Color.RED);

// Set Lable Color
generator.getParameters().getBarcode().getCodeTextParameters().setColor(Color.BLUE);

// Save the output
generator.save("C:\\Files\\Gs1CouponAppearance.jpg");

以上便是如何在Java 中的 GS1-128 条码生成器,希望能帮到您,除此之外,你有其他方面的需求,也欢迎和我们互动


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值