GS1-128

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronBarcode 是否支援 GS1 UCC/EAN-128 條碼符號?

採用 GS1 標準的 BarCode 能被精準識別與解碼。 然而,問題在於目前顯示的BarCode值中缺少括號。

當使用 GS1-128 時,IronBarcode 目前輸出:01950123456789033103000123(此格式被識別為帶有 GS1 簽名的 Code 128 BARCODE)。 圖片輸出中應顯示的目標值為:01950123456789033103000123。 然而,BARCODE掃描器會輸出 (01)95012345678903(3103)000123,並將BARCODE類型偵測為 Code128

若要產生 GS1-128 BARCODE,請使用以下程式碼:

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");
    }
}
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");
    }
}
Imports IronBarCode

Friend Class BarcodeExample
	Shared Sub Main()
		' Create a GS1-128 barcode using the specified value
		Dim barcode As GeneratedBarcode = 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")
	End Sub
End Class
$vbLabelText   $csharpLabel

輸出BarCode

BarCode輸出範例

上述程式碼會產生一個帶有預設分隔符的 GS1-128 BARCODE。 若需新增分隔符,可插入 Unicode 分隔符 \u00f1。 但請注意,當使用 AddBarcodeValueTextBelowBarcode 方法時,將顯示 Unicode 字元 ñ(代碼 0x00F1)。 為克服此限制,另一種做法是操作該字串,並將修改後的值傳遞給 AddAnnotationTextBelowBarcode 方法。 如此一來,您便能實現不包含 ñ 字元的 BarCode 值顯示效果。

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");
    }
}
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");
    }
}
Imports IronBarCode

Friend Class BarcodeExampleWithAnnotation
	Shared Sub Main()
		' Original barcode value
		Dim barcodeValue As String = "0195012345678903310300012300" & ChrW(&H00f1).ToString() & "0000000123300000" & ChrW(&H00f1).ToString() & "0000012312300000"

		' Remove unwanted unicode characters for display purposes
		Dim trimmedString As String = barcodeValue.Replace(ChrW(&H00f1).ToString(), "")

		' Create a GS1-128 barcode using the original value
		Dim barcode As GeneratedBarcode = 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")
	End Sub
End Class
$vbLabelText   $csharpLabel

輸出BarCode

帶註解的BARCODE輸出範例

掃描BARCODE時,輸出結果將為 (01)95012345678903(3103)000123(00)0000000123300000(00)00012312300000,而BARCODE類型將被偵測為 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
using IronBarCode;

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

' GS1-128 with encoding analysis
Dim gs1Result = Code128GS1Parser.ParseWithEncoding("(01)09501101530003")
Console.WriteLine(gs1Result.CharacterSetSummary)  ' "C"
Console.WriteLine(gs1Result.HasEncodingInfo)      ' True
$vbLabelText   $csharpLabel

由於 GS1-128 資料主要為數值型,編碼器採用 Code C 以達到最大緊湊度。 HasEncodingInfo 屬性確認結果中可進行編碼分析。

Curtis Chau
技術撰稿人

Curtis Chau 擁有卡爾頓大學(Carleton University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備好開始了嗎?
Nuget 下載 2,240,258 | 版本: 2026.5 just released
Still Scrolling Icon

還在捲動嗎?

想要快速證明? PM > Install-Package BarCode
執行範例 看您的字串變成 BarCode。