How to encode digits in UPC-A barcode in C# application?
The EAN-13 barcode is designed to encode numeric data only, specifically digits 0 through 9.
It does not support letters, symbols, or any non-numeric characters.
UPC-A data length
An EAN-13 barcode consists of a total of 13 digits.
These 13 digits are split into 4 distinct parts:
Country code: 2 to 3 digits (identifies the country/region of origin).
Manufacturer code: Unique code assigned to the product manufacturer.
Product code: Specific code for the individual product.
Check digit: The 13th digit, used to verify the validity of the entire barcode.
UPC-A Add-on symbols
The EAN-13 barcode supports an optional add‑on symbol with either 2 digits or 5 digits. This add‑on symbol is placed to the right of the main barcode's quiet zone.
You can generate a valid EAN‑13 barcode with add‑on using the C# Barcode Library.
Use BarcodeType.UPCA_2 for a 2‑digit add‑on symbol.
Use BarcodeType.UPCA_5 for a 5‑digit add‑on symbol.
Set the Data property to your valid EAN‑13 main barcode data.
Set the SData property to the 2‑digit or 5‑digit add‑on value.
The checksum digit of a UPC-A barcode is calculated using the module 10 algorithm.
This calculation is based on the weighted sum of all digits in the UPC number, including the system code, manufacturer code, and product code.
Using BarcodeLib C# Barcode library, the SDK will automatically calculate the check sum digit base on the input UPC-A data.
Here we will explain how to calculate the UPC-A check digit
First, identify the position (odd/even) of each digit.
Treat the right-most digit of the UPC-A number as being in an "odd" position.
Assign odd/even positions to each digit by moving from right to left.
Calculate the sum of all digits that fall in odd positions.
Multiply this sum by 3 to get the weighted odd-position total.
Calculate the sum of all digits that fall in even positions.
Add the weighted odd-position total (from step 2) and the even-position sum (from step 3) together.
Determine the checksum digit. It is the number that, when added to the total from step 4, results in a value divisible by 10.
If the total from step 4 is already evenly divisible by 10, the checksum digit is 0 (not 10, as 10 is not a single digit).
UPC-A Barcode Image Dimension Width & Height
With the C# UPC-A Barcode Generator library, you can precisely define the total size of the generated barcode image to meet your printing or display requirements.
Use the ImageWidth property to set the total width of the generated UPC-A barcode image.
Use the ImageHeight property to set the total height of the generated UPC-A barcode image.
The GS1 Standard officially recommends using the OCR-B font for the human-readable digits displayed below UPC-A barcodes.
Using the C# Barcode Library, you can modify barcode text styles using the dedicated TextFont property.
Space between text and barcode modules
Use property TextMargin to configure the margin space between UPC-A text and barcode modules.
The minimum required space between the top of the digits and the bottom of the barcode bars is 0.5X.
The standard and recommended spacing value is 1X for reliable scanning.
Show, hide UPC-A add-on symbol quiet zone indicator in C#
When creating UPC-A barcode labels with 2 or 5 digits add-on, you have the option to show or hide the quiet zone indicator.
The quiet zone indicator is a visual marker that denotes the quiet zone (empty space) required for proper barcode scanning.
By default, the C# Barcode Library automatically hides this quiet zone indicator at the end of the UPC-A barcode.
To enable and display quiet zone indicator on UPC-A barcode in C# application,
Enable the EANUPCShowIndicator property to true to show the UPC-A (with add-on) quiet zone indicator.
Customize UPC-A first and last digit settings in C#
The C# UPC-A Barcode Generator library allows you to adjust spacing and text positions for UPC-A barcodes using properties.
You can modify horizontal spacing and vertical text offsets to meet your labeling requirements.
Adjust Horizontal Spacing for UPC-A Barcode
Use the EANUPCFirstDigitShift property to increase the space between the first digit and the start bar of a UPC-A barcode.
Use the EANUPCLastDigitShift property to increase the space between the stop character and the quiet zone indicator.
Both properties help you fine-tune the barcode layout for better readability and printing.
Adjust Vertical Offset of Barcode Digits
Use the EANUPCFirstDigitShiftY property to set the vertical offset distance for the first digit in the barcode text.
Use the EANUPCLastDigitShiftY property to set the vertical offset distance for the last digit in the barcode text.
These properties apply to both UPC-A and EAN-13 barcode formats.
Customize Font Size of First and Last Digits
Use the UPCFirstLastDigitScale property to customize the font size of the first and last digits.
This property defines the size ratio between the first/last digits and all other digits in the UPC-A barcode.
Adjust the value to enlarge or reduce the font size of the leading and trailing digits.
When working with UPC-A barcodes that include add-on codes,
you can adjust add-on barcode with two key properties using the C# UPC-A Barcode Generator library.
Bar Height (SHeightRatio)
The bar height is defined as a multiplier relative to the height of the main UPC-A barcode's bar module.
Default value: 0.8 (this means the add-on barcode's height is 80% of the main UPC-A bar module height).
Adjust the multiplier to increase or decrease the add-on barcode's height as needed for your labeling requirements.
Bar Space (SSeparation)
This setting controls the horizontal space between the main UPC-A barcode and the add-on supplement bar.
Modify this value to adjust the gap between the main barcode and the add-on, ensuring proper visual separation and scannability.
Note: Avoid setting the bar space to less than 10 pixels, as insufficient spacing can lead to scanning errors or misreading of the add-on code.
Customize UPC-A Barcode bar, space, color and image settings in C#
Color Settings
With the BarcodeLib C# Barcode Library, you can generate and fully customize UPC-A barcode module and text label colors in both C# ASP.NET web applications and desktop programs. You can independently set colors for the barcode bars (foreground) and background spaces.
Configure the BarColor property to define the color of the barcode bar modules (set to red).
Configure the BackgroundColor property to define the color of the barcode space modules and quiet zones (set to light blue).
Configure the TextFontColor property to define the color of the UPC-A barcode text label.
Notes: Ensure high contrast between BarColor and BackgroundColor to maintain barcode scannability. Avoid using similar or light colors for both foreground and background.
You can use property ImageFormat choose the UPC-A barcode image output formats. The Barcode library supports vector images (SVG and EPS) and common raster images (bitmap, png, jpeg, gif).
Guide to Create UPC-A Barcodes in C# ASP.NET Web Project
Add Barcodelib.Barcode.ASP.NET.dll to your web project.
Add Barcodelib.Barcode.ASP.NET.dll to Toolbox.
Open the folder barcode in the downloaded trial package and copy files "linear.aspx", "linear.aspx.cs" to your project folder.
Drag LinearASPNET from the Toolbox and drop it on the split part of your aspx page. Then you may see a Code 128 image tag on the form.
Click the produced barcode image and change barcode type to UPC-A in the Properties Window or generate an UPC-A barcode with above C# sample codes for UPC-A barcoding.
Guide to Generate UPC-A Barcodes in C#.NET WinForms Project
Add BarcodeLib.Barcode.WinForms.dll from the trial package to your WinForms Project.
Add BarcodeLib.Barcode.WinForms.dll to your Visual Studio Toolbox.
Drag LinearWinForm to your windows form and click generated image. Then, adjust its barcode type to UPC-A in the Properties Window or create an UPC-A image with above free C# codes for UPC-A barcoding.