Quick to Create EAN-13 barcode using C#
EAN-13 barcode encodes digits (0-9) only.
EAN-13 barcode contains 12 data digits and 1 check digit. And it includes 4 parts: Country codes (2-3 digits), manufacurer code, product code and the last check digit.
Using OnBarcode Barcode Generator for C# library, you can provide 12 digits or 13 digits to barcode property Data.
If you encode EAN13 with wrong data length, the barcode library will throw exception or produce an empty image with "Invalid Barcode Settings" printed.
View details about Exception here: How to handle exception during barcode creation using C#?
EAN-13 barcode contains 12 data digits and 1 check digit. And it includes 4 parts: Country codes (2-3 digits), manufacurer code, product code and the last check digit.
Using OnBarcode Barcode Generator for C# library, you can provide 12 digits or 13 digits to barcode property Data.
Linear barcode = new Linear(); barcode.Data = "012345678912"; // 12 or 13 digits barcode.Type = BarcodeType.EAN13; barcode.drawBarcode("C://Output//barcode-sample.png");
If you encode EAN13 with wrong data length, the barcode library will throw exception or produce an empty image with "Invalid Barcode Settings" printed.
View details about Exception here: How to handle exception during barcode creation using C#?
EAN-13 Barcode Add-on Symbol
EAN-13 barcode may contain a two-digit or five-digit add-on symbol. The add-on symbol is positioned following the right Quiet Zone of the main symbol.
To create a valid EAN-13 barcode with add-on symbol, you need apply the following settings using C# barcode library.
OnBarcode Barcode Generator C# library also provides more add-on symbol customization properties. You can view the details here :
How to create and customize barcode with add-on symbol using C#?.
To create a valid EAN-13 barcode with add-on symbol, you need apply the following settings using C# barcode library.
- Set barcode Type property as
BarcodeType.EAN13_2for two digits add-on, andBarcodeType.EAN13_5for five digits add-on - Set Data with EAN 13 barcode data
- Set SupData with add-on data
Linear barcode = new Linear(); barcode.Data = "012345678912"; // 12 or 13 digits barcode.SupData = "01"; barcode.Type = BarcodeType.EAN13_2; barcode.drawBarcode("C://Output//barcode-sample-ean13-2-digit.png");
OnBarcode Barcode Generator C# library also provides more add-on symbol customization properties. You can view the details here :
How to create and customize barcode with add-on symbol using C#?.
EAN-13 barcode text (human readable interpretation)
The GS1 System recommends to use OCR-B font for digits shown under the EAN-13 barcode. Barcode library provides TextFont property to customize the
barcode text (human readable interpretation) using C#.
You can find some free font resources here: Free OCR font resources for GS1 linear barcodes.
The minimum space between the top of the digits and the bottom of the bars (dark bars) shall be 0.5X. Normally it is 1X. Barcode library provides TextMargin to set the space between bars and digits.
The C# code below explains how to customze the EAN-13 human readable interpretation and text margin.
You can find some free font resources here: Free OCR font resources for GS1 linear barcodes.
The minimum space between the top of the digits and the bottom of the bars (dark bars) shall be 0.5X. Normally it is 1X. Barcode library provides TextMargin to set the space between bars and digits.
The C# code below explains how to customze the EAN-13 human readable interpretation and text margin.
Linear barcode = new Linear(); barcode.Type = BarcodeType.EAN13; barcode.Data = "012345678912"; // 12 or 13 digits barcode.TextFont = new Font("OCR-B", 12f, FontStyle.Regular); barcode.TextMargin = 10; barcode.drawBarcode("C://Output//barcode-sample-ean13-text.png");
Create and customize EAN-13 barcode in C# ASP.NET, MVC, WinForms apps
Using OnBarcode C# Barcode Generator library, you
can apply the following barcode options to further customize the EAN-13 barcode labels in C# ASP.NET, MVC, WinForms, WPF web and desktop apps.
Here we will show how to customize the EAN-13 barcode image below using the above EAN-13 barcode options in C# class.
- ShowQuietZoneIndicator: Display or hide EAN barcode quiet zone indicator. The default value is
true. - UPCEANLeadDigitSpace: The space between the first digit and the start character bar. The default value is
0. - UPCEANTrailDigitSpace: The space between the stop character bar and the quiet zone indicator. The default value is
0.
Here we will show how to customize the EAN-13 barcode image below using the above EAN-13 barcode options in C# class.
EAN barcode quiet zone indicator
You can display or hide the EAN barcode quiet zone indicator in barcode label. By default, the C# barocde library will print
the EAN-13 barcode quiet zone indicator mark on the end of the EAN-13 barcode.
The property
The property
ShowQuietZoneIndicator will allow you to show or hide the EAN-13 quiet zone indicator.
barcode.ShowQuietZoneIndicator = false;
EAN-13 the first and last digit space
You can increase the space between the EAN-13 first code and the start bar, and the space between the stop char and quiet zone indicator through
barcode options
UPCEANLeadDigitSpace and UPCEANTrailDigitSpace.
barcode.UPCEANLeadDigitSpace = 10; barcode.UPCEANTrailDigitSpace = 10;
How to verify, calculate EAN-13 check digit using C#?
Barcode EAN-13 check sum digit is based on a module 10 calculation. Please view
How to calculate EAN-13 barcode check digit
The table below explains how to calculate EAN 13 check digit.
The table below explains how to calculate EAN 13 check digit.
For example, EAN 13 barcode data is "123456789012", and its correct check digit sum is "8".
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | 1 | 2 | |
| Step 1 | even | odd | even | odd | even | odd | even | odd | even | odd | even | odd |
| Step 2 & 3 | 1 | 6 | 3 | 12 | 5 | 18 | 7 | 24 | 9 | 0 | 1 | 6 |
| Step 4 | Total is 92 | |||||||||||
| Step 5 | The next number of 92 is 100, which will be evenly divisible by 10. | |||||||||||
| Step 5 | So the check digit is 8. (100-92=8) | |||||||||||
Create EAN-13 Barcodes in C#
View complate source code at How to generate EAN 13 barcode using C#
Tutorial: How to create, print EAN-13 barcode in C# ASP.NET Core web app?
Here we will demonstrate a step by step tutorial how to create, print EAN-13 barcode image on web page in C# ASP.NET Core web application.
After the ASP.NET Core web app is built, we will explore and enable more features
- Generate EAN-13 barcode with 2-digit add-on
- Create, print EAN-13 barcode text using OCR-B font
- Create, output EAN-13 to image files
Create new ASP.NET Core web with EAN-13 supported using C#
We already have one detailed tutorial with Code 128 barcode generation in ASP.NET Core web app using C#.
Here we will use the ASP.NET Core project fileS, and change to EAN-13 barcode generation.
If you have not created the demo project, please see here and create a new ASP.NET Core web app: How to create barcode in ASP.NET Core using C# Barcode Generator library?
Once you have finished the above ASP.NET tutorial, you can create and print a Code 128 barcode with your input text on the web page.
Here we will change the generated barcode format from Code 128 to EAN-13.
If you have not created the demo project, please see here and create a new ASP.NET Core web app: How to create barcode in ASP.NET Core using C# Barcode Generator library?
Once you have finished the above ASP.NET tutorial, you can create and print a Code 128 barcode with your input text on the web page.
Here we will change the generated barcode format from Code 128 to EAN-13.
- Open the new created ASP.NET project "OnBarcode.BarcodeGenerator.ASPNETCoreDemo" with Visual Studio .NET
- In Visual Studio Solution Explorer, click to open file "Index.cshtml.cs"
- In "OnPost()" method, find the C# code "linear.Type = OnBarcode.Barcode.BarcodeType.CODE128;".
Replace it with the new code :
"linear.Type = OnBarcode.Barcode.BarcodeType.EAN13;"
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace OnBarcode.BarcodeGenerator.ASPNETCoreDemo.Pages { public class IndexModel : PageModel { public String Message { get; set; } = ""; public String BarcodeImage { get; set; } = ""; public void OnGet() { } public Task<IActionResult> OnPost() { this.Message = Request.Form["tbMessage"].ToString(); OnBarcode.Barcode.Linear linear = new OnBarcode.Barcode.Linear(); linear.Type = OnBarcode.Barcode.BarcodeType.EAN13; linear.Data = this.Message; linear.OutputFileFormat = FileFormat.PNG; byte[] dataBytes = linear.drawBarcodeAsBytes(); BarcodeImage = System.Convert.ToBase64String(dataBytes); return Task.FromResult<IActionResult>(Page()); } } }
- Now your customized ASP.NET Core app supports EAN-13 barcode generation in web browse. You can run the web app and input 12 or 13 digits on text box "Barcode Message". And press "Create Barcode" button to print the EAN-13 barcode image below in web page.
Create EAN-13 with addon digits in C# ASP.NET Core web app
Here we will show how to generate, print EAN-13 barcode with add-on 2 or 5 digits on web page in the previewly created C# ASP.NET Core web application.
Again, open the file "Index.cshtml.cs" in Visual Studio Solution Explorer.
Go to "OnPost()" method, please replace the following C# code
In the previous C# code, we will define the EAN-13 barcode formats based on the web user input message.
Now you can run the ASP.NET Core web app from Visual Studio, and input EAN-13 12 or 13 digits with "+" and 2 or 5 digits to create EAN-13 barcode with addon on the web browser.
Again, open the file "Index.cshtml.cs" in Visual Studio Solution Explorer.
Go to "OnPost()" method, please replace the following C# code
public Task<IActionResult> OnPost() { this.Message = Request.Form["tbMessage"].ToString(); OnBarcode.Barcode.Linear linear = new OnBarcode.Barcode.Linear(); { string inputData = this.Message; string barcodeData = ""; string barcodeAddonData = ""; int idx = inputData.IndexOf("+"); if (idx >= 0) { barcodeData = inputData.Substring(0, idx); barcodeAddonData = inputData.Substring(idx + 1); if (barcodeAddonData.Length == 2) { linear.Type = OnBarcode.Barcode.BarcodeType.EAN13_2; } else if (barcodeAddonData.Length == 5) { linear.Type = OnBarcode.Barcode.BarcodeType.EAN13_5; } linear.Data = barcodeData; linear.SupData = barcodeAddonData; } else { linear.Type = OnBarcode.Barcode.BarcodeType.EAN13; linear.Data = inputData; } } byte[] dataBytes = linear.drawBarcodeAsBytes(); BarcodeImage = System.Convert.ToBase64String(dataBytes); return Task.FromResult<IActionResult>(Page()); }
In the previous C# code, we will define the EAN-13 barcode formats based on the web user input message.
-
If the user input data is ended with "+" and 2 digits, the barcode format will be EAN-13 barcode with 2 digits addon
linear.Type = OnBarcode.Barcode.BarcodeType.EAN13_2;
-
If the user input data is ended with "+" and 5 digits, the barcode format will be EAN-13 barcode with 5 digits addon
linear.Type = OnBarcode.Barcode.BarcodeType.EAN13_5;
-
Otherwise, the barcode format is EAN-13 without any add-on
linear.Type = OnBarcode.Barcode.BarcodeType.EAN13;
Now you can run the ASP.NET Core web app from Visual Studio, and input EAN-13 12 or 13 digits with "+" and 2 or 5 digits to create EAN-13 barcode with addon on the web browser.
Print EAN-13 with barcode text using OCR font in ASP.NET Core
The GS1 specification recommends that the linear barcodes (including EAN-13) use OCR-B font to print barcode human readable text.
If your computer has installed the OCR-B font, you can easily apply the EAN-13 barcode text font to "OCR-B" using TextFont property in Linear class. Or you can download free OCR font file here: How to create, print GS1 linear barcode text with OCR-B font using C#?
You can add the following C# code to "OnPost()" method in the file "Index.cshtml.cs".
If your computer has installed the OCR-B font, you can easily apply the EAN-13 barcode text font to "OCR-B" using TextFont property in Linear class. Or you can download free OCR font file here: How to create, print GS1 linear barcode text with OCR-B font using C#?
You can add the following C# code to "OnPost()" method in the file "Index.cshtml.cs".
linear.TextFont = new Font("OCR-B", 16f, FontStyle.Regular);
Create EAN-13 barcode image with multiple formats using C#
You can quickly generate and print user created EAN-13 barcodes to multiple image formats in ASP.NET web application. C# Barcode Geneator Library supports
barcode generation in
You can add the above C# sample code to the "OnPost()" method in the file "Index.cshtml.cs", and save the barcode image to an image file path.
- SVG. A vector image format for web and Windows system.
linear.OutputFileFormat = OnBarcode.Barcode.FileFormat.SVG;
- EPS. A vector image format.
linear.OutputFileFormat = OnBarcode.Barcode.FileFormat.EPS;
- BITMAP
linear.OutputFileFormat = OnBarcode.Barcode.FileFormat.BMP;
- GIF
linear.OutputFileFormat = OnBarcode.Barcode.FileFormat.GIF;
- JPG
linear.OutputFileFormat = OnBarcode.Barcode.FileFormat.JPG;
- PNG. The default barcode output image file format.
linear.OutputFileFormat = OnBarcode.Barcode.FileFormat.PNG;
- TIFF
linear.OutputFileFormat = OnBarcode.Barcode.FileFormat.TIF;
You can add the above C# sample code to the "OnPost()" method in the file "Index.cshtml.cs", and save the barcode image to an image file path.
linear.drawBarcode("barcode-filepath.png");
Common Asked Questions
What is the EAN-13 code?
EAN-13 is a 13-digit barcode, which includes 12 GS1 data digits and 1 check digit. EAN is short for European Article Number,
and now it is renamed as GTIN (Global Trade Item Number). EAN 13 code will be used to uniquely identify retail products worldwide.
In C# class, you can input EAN-13 12 digits data text or whole 13 digits with check sum, the C# barcode generator library will generate and print the EAN13 barcodes in C# ASP.NET, MVC, Windows applications.
In C# class, you can input EAN-13 12 digits data text or whole 13 digits with check sum, the C# barcode generator library will generate and print the EAN13 barcodes in C# ASP.NET, MVC, Windows applications.
What is the difference between EAN and EAN-13?
EAN barcode includes EAN-13, EAN-8. You can use C# barcode library to encode and print EAN-13, and EAN-8 barcode images easily in C# applications.
What is the EAN-13 barcode layout?
The whole 13 digits EAN-13 code is grouped as follows:
You will find more information here: EAN-13 barcode data structure.
- 2 or 3 digits for the number system or the country code
- 5 or 4 digits for the manufacturer code or prefix
- 5 digits for the product code
- 1 digit for the check digit
You will find more information here: EAN-13 barcode data structure.
How to check if the EAN-13 barcode created using C# is valid?
The last digit of EAN-13 is a check digit. It will be used to verify the first 12-digit GS1 data message.
Using C# barcode library,
the generated EAN-13 barcode check digit is calculated and verified by the barcode SDK.
What is the minimum size for EAN-13?
The GS1 recommended minimum size for an EAN-13 barcode is 30mm in width and 20 mm in height.
You can customize the EAN-13 barcode image with and height through barcode property
BarcodeWidth and BarcodeHeight in C# class.
How do I print high quality EAN-13 barcodes in ASP.NET, Windows apps?
To print good quality EAN-13 barcodes in .NET apps, you need follow the rules below.
- The EAN-13 barcode image resolution (DPI) is the same or higher than the printer's resolution.
In C# class, customize the barcode image resolution through property
Resolution - The EAN-13 barcode human readable text is using the legible fonts. The GS1 System recommends use OCR-B font to draw EAN-13 text label.
Here is the sample C# code to apply fonts.new Font("OCR-B", 16f, FontStyle.Regular)
Summary
OnBarcode C# Barcode Generator makes it easy to generate, create EAN-13 and other linear & 2d barcodes in .NET projects.
Here are some detailed tutorials for C# EAN-13 generation and data encoding, size & image setting.
OnBarcode provides several EAN-13 Generator components and software, including Excel EAN-13, Java EAN-13, VB.NET EAN-13, ASP.NET EAN-13, EAN-13 Generator.
OnBarcode provides several EAN-13 Generator components and software, including Excel EAN-13, Java EAN-13, VB.NET EAN-13, ASP.NET EAN-13, EAN-13 Generator.
