How to read GS1 data from barcode images in C#?

How to scan, read, parse GS1 data elements from barcode images for ASP.NET Core web app and Windows application?

Using Free C# Souce Code to Generate GS1 Barcode Labels for ASP.NET Web Application & Windows Applications



The following guide will help you how to read GS1 data message from GS1 supported barcode using C#. Parse the extracted GS1 data message with control characters into list of GS1 Application Identifier (AI Code) and a GS1 Application Identifier data field.

After this tutorial, you will be albe to
  • Scan, read GS1 data elements from barcode image directly using C#
  • Extract the GS1 data with special characters from barcode in C#
  • Support .NET 7, 6, 5 and .NET Core 3.1, 2.1 ASP.NET Core, WinForms, WPF .NET Windows application

How to read, parse GS1 data elements from barcode images using C#?

  1. Download C#.NET Barcode Reader Library
  2. Install C# library to read GS1 barcode images in .NET applications
  3. Step by Step Tutorial








About GS1 data message

Top
A GS1 data message contains a group data elements. Each element string is the combination of a GS1 Application Identifier (AI Code) and a GS1 Application Identifier data field (AI Data). The AI Code is a two to four digits number.

The GS1 data message could be encoded in independent of data carrier, such as barcode, RFID (radio frequency identification), and business message.

A GS1 barcode contains a group of data elements with several special characters (such as FNC1)

The GS1 barcode complete data includes list pairs of AI code and data, and some control characters, such as "FNC1". The FNC1 is a non-printable control character used to delimit GS1 element strings of variable length.

How to read GS1 data from barcodes using C#

Top


In the following C# example, we will use a sample GS1 data "(01)09012345678901(17)240915(10)abc123(3930)978112". The sample GS1 data includes FOUR elements with four application identifier (AI Code): "01", "17", "10", "3930".

  • 01 - GTIN (identification of a trade item). The AI Code will be followed by 14 digits

  • 17 - Expiration date. The AI Code will be followed by 6 digits. the example here is Sep 15, 2024

  • 10 - BATCH/LOT: batch or lot number. The AI Code will be followed by data in variable length.

  • 3930 - Amount payable. The AI Code will be followed by 3 digits ISO currency code with applicable amount payable. The data is in variable length. The example here is Euro 112.00


We have encoded the above GS1 data into GS1-128, QR Code and Data Matrix barcodes using OnBarcode C# Barcode Generator library.

GS1-128


QR Code


Data Matrix


Now you can use our C# barcode reader library to scan, read the above barcodes. Here is the C# sample source code to read GS1-128 barcodes.

            string inputFilePath = "W://Projects//Test-Input//gs1-sample-data-gs1-128.png";
            //  Scan barcodes from the input image file.
            BarcodeDetail[] result = BarcodeScanner.ScanInDetails(inputFilePath, BarcodeType.Code128);
            foreach (BarcodeDetail b in result)
            {
                //  Indicate if the barcode is conform to GS1 specification.
                if (b.IsGS1Compitable)
                {
                    //  Get message in string format.
                    //  Eg. "(415)5412345678908(3911)710125"
                    String msg = b.GetMessage();
                    Console.WriteLine("Data: '{0}'", b.Data);
                    Console.WriteLine("Message: {0}", msg);
                    //  Retrieve each AI and its data from the message.
                    //  Eg.
                    //  AI:   415
                    //  Data: 5412345678908
                    //  AI:   3911
                    //  Data: 710125
                    String[] vals = msg.Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < vals.Length; i += 2)
                    {
                        Console.WriteLine("AI:    {0}", vals[i]);
                        Console.WriteLine("Data:  {0}", vals[i + 1]);
                    }
                }
            }


Output in the console window:

Data: '01090123456789011724091510abc1233930978112'
Message: (01)09012345678901(17)240915(10)abc123(3930)978112
AI:    01
Data:  09012345678901
AI:    17
Data:  240915
AI:    10
Data:  abc123
AI:    3930
Data:  978112


In the data message, there are two characters are special characters (non-printable), which are defined by GS1.

In the class BarcodeDetail, we have provided a useful method GetMessage(). The message will automatically parse the scanned data message into GS1 data elements.



Conclusion

Using OnBarcode C# barcode reader library, you do not need parse the control characters inside the GS1 barcode data message. Call barcode reader library, you can get the GS1 barcode all elements directly.

















OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.