Quick to generate UPC-A barcode in C# app
It is easy to create, print UPC-A barcode image using C# Barcode Generator library.
After running the above C# code, you will get the following UPC-A barcode image file.
- Crate a new Linear object, which allows you to create a linear barcode.
- Set the Data property to 11 digits. The property accept UPC-A data in 11 or 12 digits.
- Set the barcode format as "BarcodeType.UPCA"
- Use drawBarcode() to create UPC-A and print to a png image file.
Linear barcode = new Linear(); barcode.Data = "12345678912"; barcode.Type = BarcodeType.UPCA; barcode.drawBarcode("C://Output//barcode-upca-sample.png");
After running the above C# code, you will get the following UPC-A barcode image file.
Print and customize UPC-A barcode in C# ASP.NET, MVC, WinForms apps
Using OnBarcode C# Barcode Generator library,
you can print and customize UPC-A barcode using the following barcode options in C# ASP.NET, MVC, WinForms, WPF web and desktop apps.
Here we will show how to customize the UPC-A barcode images below using the above UPC-A barcode options in C# class.
- ShowQuietZoneIndicator: Display or hide UPC 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. - UPCEANLeadTrailDigitSizeRatio: The first and last digit font size vs the rest digits font size. The default value is
1.0f
Here we will show how to customize the UPC-A barcode images below using the above UPC-A barcode options in C# class.
UPC add-on quiet zone indicator
You can display or hide the UPC-A with add-on barcode quiet zone indicator in barcode label. By default, the C# barocde library will print
the UPC quiet zone indicator mark on the end of the UPC-A barcode.
The property
The property
ShowQuietZoneIndicator will allow you to hide the UPC-A with add-on quiet zone indicator.
barcode.ShowQuietZoneIndicator = false;
Note:
- Do not hide the quiet zone indicator unless your printing or scanning scenario specifically requires it.
- The quiet zone is critical for scanners to accurately read the UPC-A barcode. Hiding the indicator does not remove the quiet zone itself, but only the visual marker.
- Ensure your barcode label still maintains the required quiet zone space even if the indicator is hidden to avoid scanning errors.
UPC-A the first, last digit space, position and font size
Using C# UPC-A Barcode Generator library, you can increase the space between the UPC-A first code and the start bar, and the space between the stop char and quiet zone indicator through
barcode options
Use the following properties to adjust the vertical offset distance of the first and last digit in the UPC-A barcode text.
UPCEANLeadDigitSpace and UPCEANTrailDigitSpace.
Use the following properties to adjust the vertical offset distance of the first and last digit in the UPC-A barcode text.
UPCEANLeadDigitYShiftfor the first digit in the EAN-13 barcode textUPCEANTrailDigitYShiftfor the last digit in the EAN-13 barcode text
UPCEANLeadTrailDigitSizeRatio. The option value is
the first and last digit font size vs the rest digits font size.
barcode.UPCEANLeadDigitSpace = 10; barcode.UPCEANTrailDigitSpace = 10; barcode.UPCEANLeadDigitYShift = -20; barcode.UPCEANTrailDigitYShift = -20; barcode.UPCEANLeadTrailDigitSizeRatio = 0.6f;
How to calculate UPC-A check digit using C#?
Barcode UPC-A checksum digit is based on a module 10 calculation,
based on the weighted sum of the values of each of the digits in the UPC number system, menufacturer code, and product code.
The steps below explain how to calculate UPC-A checksum digit.
The steps below explain how to calculate UPC-A checksum digit.
- Consider the right-most digit of the message to be in an "odd" position, and assign odd/even to each character moving from right to left.
- Sum the digits in all odd positions, and multiply the result by 3.
- Sum the digits in all even positions.
- Sum the totals calculated in steps 2 and 3.
- The check digit is the number which, when added to the totals calculated in step 4, result in a number evenly divisible by 10.
- If the sum calculated in step 4 is evenly disivisible by 10, the check digit is "0" (not 10).
For example, UPC-A barcode data is "12345678901", and its correct check digit sum is "2".
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | 1 | ||
| Step 1 | odd | even | odd | even | odd | even | odd | even | odd | even | odd | |
| Step 2 & 3 | 3 | 2 | 9 | 4 | 15 | 6 | 21 | 8 | 27 | 0 | 3 | |
| Step 4 | Total is 98 | |||||||||||
| Step 5 | The next number of 98 is 100, which will be evenly divisible by 10. | |||||||||||
| Step 5 | So the check digit is 2. (100-98=2) | |||||||||||
Tutorial: How to create, print EAN-13 barcode in C# ASP.NET Core web app?
In the following tutorial, we will show you how to create UPC-A barcode image in web browser in C# ASP.NET Core web application.
Create new ASP.NET Core web with UPC-A supported using C#
Before we start this tutorial, you need build a new ASP.NET Core web app. After it, you will be able to
generate and print a Code 128 barcode online in the web browser.
See details here: How to create barcode in ASP.NET Core using C# Barcode Generator library?
Now we will change the build ASP.NET Core web app to create UPC-A online.
See details here: How to create barcode in ASP.NET Core using C# Barcode Generator library?
Now we will change the build ASP.NET Core web app to create UPC-A online.
- Open the ASP.NET Core project "OnBarcode.BarcodeGenerator.ASPNETCoreDemo" using Visual Studio
- In Solution Explorer, open file "Index.cshtml.cs"
- Go to "OnPost()" method, find the C# code "linear.Type = OnBarcode.Barcode.BarcodeType.CODE128;".
Change the source code to
"linear.Type = OnBarcode.Barcode.BarcodeType.UPCA;"
public Task<IActionResult> OnPost() { this.Message = Request.Form["tbMessage"].ToString(); OnBarcode.Barcode.Linear linear = new OnBarcode.Barcode.Linear(); linear.Type = OnBarcode.Barcode.BarcodeType.UPCA; linear.Data = this.Message; linear.OutputFileFormat = FileFormat.PNG; byte[] dataBytes = linear.drawBarcodeAsBytes(); BarcodeImage = System.Convert.ToBase64String(dataBytes); return Task.FromResult<IActionResult>(Page()); } - Now you can run the web app, and create UPC-A barcode online in the web browser.
Print UPC-A text using OCR-B font using C#
The GS1 Specification recommends use OCR-B font to print UPC-A barcode text label. Here we will customize the above ASP.NET Core project
to support OCR-B font in UPC-A text label.
Before start it, you need have OCR-B font installed in your computer system. See details here: How to download & install OCR-B font for GS1 barcode text label printing?
Once the OCR-B font is installed in your system, you can try to add the C# code below to "OnPost()" method in the file "Index.cshtml.cs".
When you deploy the ASP.NET Core web app to the web server, you need make sure the web server has installed OCR-B font also.
Before start it, you need have OCR-B font installed in your computer system. See details here: How to download & install OCR-B font for GS1 barcode text label printing?
Once the OCR-B font is installed in your system, you can try to add the C# code below to "OnPost()" method in the file "Index.cshtml.cs".
linear.TextFont = new Font("OCR-B", 16f, FontStyle.Regular);
When you deploy the ASP.NET Core web app to the web server, you need make sure the web server has installed OCR-B font also.
Common Asked Questions
What is a GTIN-12 UPC-A barcode?
GTIN-12 is a 12 digits Global Trade Item Number. It is usually encoded in UPC-A barcode. The 12 digits Global Trade Item Number includes 11 digits of data message,
and one digit of check sum digit. Using C# Barcode Library, you can input 12-digit GS1 numeric data or 13-digits data with checksum digit in C# code.
What is the minimum & maximum size for a UPC-A barcode?
- The Minimum X-dimension for the UPC-A barcode is 0.0104 inches.
- The Maximum X-dimension for the UPC-A barcode is 0.0260 inches
X in C# class using C# Barcode Generator library.
What is the difference between EAN-13 and UPC-A?
UPC-A Format barcodes have traditionally been used in the North America (USA and Canada), whereas EAN-13 format barcodes have been used throughout the rest of the world.
C# Barcode Generator SDK supports both UPC-A and EAN-13 with add-on symbol barcode generation in C# ASP.NET web and Windows apps.
What is the difference between UPC-A and UPC-E?
UPC-A is a 12-digit barcode, and UPC-E is a compressed UPC-A with 6 digits code. The UPC-E will be used in limited space for a barcode.
You can create both UPC-A and UPC-E images in C# ASP.NET, Windows Forms app using C# barcode library.
Summary
OnBarcode C# Barcode Generator makes it easy to generate, create UPC-A and other linear & 2d barcodes in C# ASP.NET and Windows applications.
Here are some detailed tutorials for C# UPC-A generation and data encoding, size & image setting.
OnBarcode provides several UPC-A Generator components and software, including Excel UPC-A, Java UPC-A, VB.NET UPC-A, ASP.NET UPC-A, UPC-A Generator.
OnBarcode provides several UPC-A Generator components and software, including Excel UPC-A, Java UPC-A, VB.NET UPC-A, ASP.NET UPC-A, UPC-A Generator.