Quick to Create GS1-128 Image using C#
GS1 128 barcode data includes a list of GS1 AI (Application Identifier) Code and Data pairs. One AI code is a number inside the parenthesis, and followed by its data.
You can quickly create and print a GS1-128 barcode image using C# Barcode Generator Library.
You can quickly create and print a GS1-128 barcode image using C# Barcode Generator Library.
- Create a new Linear object
- Choose the barcode format as BarcodeType.EAN128 in property Type
- Set the Data with the encoding GS1 128 data message
- Call drawBarcode() method to create and print GS1 128 to an image file
Linear barcode = new Linear(); barcode.Type = BarcodeType.EAN128; barcode.Data = "(00)395123451234567895(01)09501101530003"; barcode.drawBarcode("C://Output//barcode-sample.png");
GS1-128 Barcode Basic Characteristics in C#
Encodable character set
- The subset of ISO/IEC 646 International Reference Version defined in these GS1 General Specifications be used for GS1 Application Identifier (AI) element strings.
- Characters with ASCII values 128 to 255 may also be encoded in Code 128 symbols.
- Four non-data function characters: FNC1, FNC2, FNC3, FNC4. FNC2 and FNC4 are not used in GS1-128 barcodes.
- Four code set selection characters (including single character code set shift)
- Three start characters
- One stop character
Note: Using C#.NET Barcode Generator library, you shall not add function characters, code set selection characters, start and stop characters. OnBarcode barcode
generator library will insert them into the GS1-128 barcode symbol automatically.
GS1-128 check digit character
Same as Code 128, GS1-128 barcode has one mandatory symbol check character. The check digit character will not be displayed in the HRI (human readable interpretation).
In GS1-128 barcode generator C# library, the property AddCheckSum is not applicable. The barcode encoder library will automatically add one check character before the stop character in every GS1-128 barcode symbol.
In GS1-128 barcode generator C# library, the property AddCheckSum is not applicable. The barcode encoder library will automatically add one check character before the stop character in every GS1-128 barcode symbol.
GS1-128/EAN-128 Barcode Dimension Size in C#
In GS1-128 barcode generator C# library, you may use the following barcode dimension size properties:
- UOM: Unit of measure. Three options: PIXEL, CM and INCH.
- X: Width of the narrow element. The mimumum bar width is defined by the application specification
- Y: Height of the bar module.
- LeftMargin, RightMargin: Quiet zone. the minimum width of quiet zone is 10X.
C#.NET source code: set GS1-128 barcode image sizes.
Linear barcode = new Linear(); barcode.Data = "(00)395123451234567895(01)09501101530003"; barcode.Type = BarcodeType.EAN128; /* * Barcode Image Related Settings */ // Unit of meature for all size related setting in the library. barcode.UOM = UnitOfMeasure.PIXEL; // Bar module width (X), default is 1 pixel; barcode.X = 2; // Bar module height (Y), default is 60 pixel; barcode.Y = 60; // Barcode image left, right, top, bottom margins. Defaults are 0. barcode.LeftMargin = 0; barcode.RightMargin = 0; barcode.TopMargin = 0; barcode.BottomMargin = 0; // Image resolution in dpi, default is 72 dpi. barcode.Resolution = 300; // Created barcode orientation. //4 options are: facing left, facing right, facing bottom, and facing top barcode.Rotate = Rotate.Rotate0; barcode.drawBarcode("C://Output//csharp-gs1-128-barcode-size.png");
Tutorial: Create GS1-128 image in C# ASP.NET Core web app
In the following content, we will explain that how to build an ASP.NET Core web application with GS1-128 barcode generation enabled, and customize the barcode
with more GS1 128 features.
In this tutorial, you:
In this tutorial, you:
- Apply OCR font on GS1-128 text label, which is recommended by GS1 Standard
- Resize GS1-128 barcode width and height
- Style the GS1-128 by modifying bar and space colors
- Print GS1-128 barcode to image file with transparency background color
Build a new ASP.NET Core app with GS1-128 generation using C#
We will re-use the previously built ASP.NET Core web app. You can see details here:
How to create barcode in ASP.NET Core web app using C#?.
Now we will start to update the C# source code to enable GS1-128 barcode image generation in the ASP.NET Core application.
Now we will start to update the C# source code to enable GS1-128 barcode image generation in the ASP.NET Core application.
- Open the project "OnBarcode.BarcodeGenerator.ASPNETCoreDemo" using Visual Studio
- Find and open file "Index.cshtml.cs" in Visual Studio
- Navigate to "OnPost()" method, find the C# code "linear.Type = OnBarcode.Barcode.BarcodeType.CODE128;".
Replace it with the new code :
"linear.Type = OnBarcode.Barcode.BarcodeType.EAN128;"
public Task<IActionResult> OnPost() { this.Message = Request.Form["tbMessage"].ToString(); OnBarcode.Barcode.Linear linear = new OnBarcode.Barcode.Linear(); linear.Type = OnBarcode.Barcode.BarcodeType.EAN128; linear.Data = this.Message; linear.OutputFileFormat = FileFormat.PNG; byte[] dataBytes = linear.drawBarcodeAsBytes(); BarcodeImage = System.Convert.ToBase64String(dataBytes); return Task.FromResult<IActionResult>(Page()); } - Now the ASP.NET Core application will create GS1-128 barcode on the web page by default. You can keyin the GS1 data message on the "Barcode Message" text box to print GS1-128 on the web browser.
Print GS1-128 barcode text using OCR font in ASP.NET Core
The GS1 standard specifies that GS1-128 barcode symbol should use a clearly legible font, and OCR-B font will be recommended.
You can download and install free OCR-B font on your system. See details here: How to create, print GS1 linear barcode text with OCR-B font using C#?
Add the C# code below to "OnPost()" method in the file "Index.cshtml.cs".
The GS1-128 barcode image above is using the OCR-B font to print barcode text.
You can download and install free OCR-B font on your system. See details here: How to create, print GS1 linear barcode text with OCR-B font using C#?
Add the C# code below to "OnPost()" method in the file "Index.cshtml.cs".
linear.TextFont = new Font("OCR-B", 16f, FontStyle.Regular);
The GS1-128 barcode image above is using the OCR-B font to print barcode text.
Resize GS1-128 barcode image width and height in C#
You can create and print GS1 128 barcode image with specified image width and height using barcode library.
By default the above barcode will be generated image with 1056 pixels in width, and 250 pixels in height. Now we have changed to 528 pixels in width, and 125 pixels in height.
If you need know more about barcode image width and height settings, see the details here: How to create, print barcode with specified dimension width/height in C#?
- BarcodeWidth: the attribute specifies the generated barcode image width in pixel
- BarcodeHeight: the attribute specifies the generated barcode image height in pixel
barcode.BarcodeWidth = 528; barcode.BarcodeHeight = 125;
By default the above barcode will be generated image with 1056 pixels in width, and 250 pixels in height. Now we have changed to 528 pixels in width, and 125 pixels in height.
If you need know more about barcode image width and height settings, see the details here: How to create, print barcode with specified dimension width/height in C#?
Style GS1-128 barcode with bar and space color changed
You can modify the GS1-128 barcode bar, space and text colors using the following properties defined in class Linear
Now you will view the printed GS1-128 barcode image on the webpage with bar and text in purple color and space in light blue color.
- ForeColor: the attribute specifies the barcode bar modules' color
- BackColor: the attribute specifies the barcode space modules' color
- TextColor: the attribute specifies the linear barcode text label's color
barcode.ForeColor = Color.Purple; barcode.BackColor = Color.LightBlue; barcode.TextColor = Color.Purple;
Now you will view the printed GS1-128 barcode image on the webpage with bar and text in purple color and space in light blue color.
Create GS1-128 image file with transparency background color using C#
OnBarcode C# Barcode library supports barcode image generation with transparency background color in
PNG image format.
Here we will demonstrate how to create GS1-128 image with transparency background in C# ASP.NET Core web application.
Add the C# sample code below to the "OnPost()" method in the file "Index.cshtml.cs".
In the previous C# code,
Here we will demonstrate how to create GS1-128 image with transparency background in C# ASP.NET Core web application.
Add the C# sample code below to the "OnPost()" method in the file "Index.cshtml.cs".
barcode.ForeColor = Color.White; barcode.BackColor = Color.Transparent; barcode.TextColor = Color.White; barcode.OutputFileFormat = FileFormat.PNG;
In the previous C# code,
- Set the ForeColor and TextColor as white color
- Set the BackColor as "Color.Transparent".
The above image is displayed in a div tag with gray background color.
GS1 128 barcode property settings in C#
OnBarcode C# Barcode Generator library includes 30+ property settings to create and customize GS1-128 barcode images.
You can see the complete list of GS1-128 barcode property settings here.
And view detailed C# sample source code to generate GS1-128 barcode images in C# application at How to generate GS1-128 using C#
And view detailed C# sample source code to generate GS1-128 barcode images in C# application at How to generate GS1-128 using C#
Common Asked Questions
What is the content of GS1-128?
GS1-128 barcode can contain up to 48 characters of GS1 data information. It may encode logistical information, such as batch/lot numbers, product serial number,
produce date, expiration date, weights, price.
OnBarcode C#/Java Barcode Generator library supports GS1 data message encoding in GS1 supported barcode formats, including GS1-128, GS1 QR Code, Data Matrix, ITF-14, GS1 DataBar.
What is the function code for GS1-128?
The GS1-128 barcode supports one function code Function Code 1 (FNC1). The FNC1 character should be encoded after GS1 start character.
Using C# Barcode Generator SDK, the barcode software will automatically encode the FNC1 character in the right position in the 128 barcode in C# codes.
What is the minimum & maximum size for GS1-128 barcode?
- The minimum width for the X-dimension (the width of the narrowest bar or space) is 0.495 mm.
- The maximum width for the X-dimension is 1.016 mm
X in C# codes.
What is the difference between GS1-128 and GTIN 14?
Both barcode formats encode GS1 business data messages.
The GS1-128 barcode can encode multiple GS1 application identities (ID) and their data information, such as serial number, price, production dates.
The GTIN 14 (also known as ITF-14, based on Interleaved 2 of 5) can only encode the 14 digits Global Trade Item Number (GTIN).
OnBarcode C# Barcode library allows C# developers easily generating GS1-128 and ITF-14 barcode with GS1 data encoding in C# applications.s
OnBarcode C# Barcode library allows C# developers easily generating GS1-128 and ITF-14 barcode with GS1 data encoding in C# applications.s
What is the difference between Code 128 and GS1-128?
GS1-128 (also known as EAN-128) is an application of Code 128 required by GS1 System. GS1-128 encodes a subset of Code 128 encoding characters.
Using C# Barcode Generator library, you can easily create and customize Code 128 and GS1-128 barcode images in C# ASP.NET, MVC, WinForms, WPF apps.
Summary
OnBarcode C# Barcode Generator makes it easy to generate, create GS1-128 and other linear & 2d barcodes in .NET web and Windows apps.
OnBarcode provides several GS1-128 Generator components and software, including GS1 128 Excel add-in, GS1 128 Java, GS1 128 VB.NET, GS1 128 ASP.NET, GS1 128 Generator.
OnBarcode provides several GS1-128 Generator components and software, including GS1 128 Excel add-in, GS1 128 Java, GS1 128 VB.NET, GS1 128 ASP.NET, GS1 128 Generator.