IRONSOFTWAREHOME

GS1-128

Curtis Chau
Curtis Chau
Updated: 2026年4月22日

IronBarcode 是否支持 GS1 UCC/EAN-128 条码体系?

采用 GS1 标准的条形码能够被准确识别和解码。 然而,问题在于目前显示的条形码值缺少括号。

使用GS1-128时,IronBarcode目前输出:01950123456789033103000123(被识别为带有GS1标记的Code 128条码)。 想要在图像输出中显示的值是:01950123456789033103000123。 然而,条码扫描器将输出Code128

要生成 GS1-128 条形码,请使用以下代码:

using IronBarCode;

class BarcodeExample
{
    static void Main()
    {
        // Create a GS1-128 barcode using the specified value
        GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("01950123456789033103000123", BarcodeWriterEncoding.Code128GS1);

        // Add the barcode value text below the barcode on the generated image
        barcode.AddBarcodeValueTextBelowBarcode();

        // Save the barcode image as a PNG file
        barcode.SaveAsPng("gs1code128.png");
    }
}

输出条形码

条码输出示例

上述代码生成带有默认分隔符的 GS1-128 条形码。 如果想要添加额外的分隔符,可以插入Unicode分隔符\u00f1。 但是,请注意,当使用AddBarcodeValueTextBelowBarcode方法时,Unicode字符ñ(代码0x00F1)将被显示。 为克服这一限制,可采用替代方法操作字符串,并将修改后的值传递给AddAnnotationTextBelowBarcode方法。 这样,您就可以在不显示 ñ 字符的情况下实现所需的条形码值显示。

using IronBarCode;

class BarcodeExampleWithAnnotation
{
    static void Main()
    {
        // Original barcode value
        string barcodeValue = "0195012345678903310300012300\u00f10000000123300000\u00f10000012312300000";
        
        // Remove unwanted unicode characters for display purposes
        string trimmedString = barcodeValue.Replace("\u00f1", "");

        // Create a GS1-128 barcode using the original value
        GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(barcodeValue, BarcodeWriterEncoding.Code128GS1);

        // Add a custom annotation text below the barcode with the trimmed value
        barcode.AddAnnotationTextBelowBarcode(trimmedString);

        // Save the barcode image as a PNG file
        barcode.SaveAsPng("gs1code128.png");
    }
}

输出条形码

带注释的条码输出示例

扫描条码时,输出将是GS1Code128

分析 GS1-128 编码

IronBarcode 还能分析 GS1-128 条形码的物理编码,显示数据的每个段落使用了哪种 Code 128 字符集(A、B 或 C)。 使用Code128GS1Parser.ParseWithEncoding方法解析包含编码分析的GS1字符串。

using IronBarCode;

// GS1-128 with encoding analysis
var gs1Result = Code128GS1Parser.ParseWithEncoding("(01)09501101530003");
Console.WriteLine(gs1Result.CharacterSetSummary);  // "C"
Console.WriteLine(gs1Result.HasEncodingInfo);      // true

由于 GS1-128 数据主要为数字,编码器采用 Code C 编码方式以实现最大紧凑性。 HasEncodingInfo属性确认在结果上可用编码分析。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

...
阅读更多

准备开始了吗?

Nuget Downloads 2,422,100版本:2026.9刚刚发布

立即获取您的免费30 天试用密钥
无需信用卡或创建账户
C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索 "IronBarcode"
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.9

  1. 下载并将 IronBarCode 解压到解决方案目录中的 ~/Libs 等位置
  2. 在 Visual Studio 解决方案资源管理器中,右键单击引用。选择浏览,"IronBarcode.dll"

许可 $999

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户