Setting UPC-E Barcode Size in C#
How to generate, print barcode using .NET, Java sdk library control with example project source code free download:
Controling UPC-E Barcode Size in C#
OnBarcode provides customers with complete
UPC-E barcode generating and scanning components for Java, .NET, Android, iOS developments and several reporting applications.
UPC-E Structure
- W : the width of UPC-E barcode image, including quiet zones.
- X : the width of UPC-E narrowest bar; X min = 1 pixel.
- C : the number of UPC-E encoded data characters, including the check digit; C =6.
- Q : the width of the quiet zone; Q > = 7X; Q (L) = 9X, Q (R) = 7X.
UPC-E Barcode Width
Basic information you should know
According to GS1 specification, the barcode width of UPC-E (W), measured in pixel, can be calculated as follows.
- UPC-E with no supplement data character,
W min = ( C * 7 + 9 ) X + 2Q       // C = 6, Q (L) = 9X, Q (R) = 7X.
= ( 6 * 7 + 9 ) X + 9X + 7X
= 67X
= 67 pixel
- UPC-E Two-digit Add-On. W = 92X. W min = 92 pixel.
- UPC-E Five-digit Add-On, W = 119X. W min = 119 pixel.
As to Our UPC-E barcode generators, the value of each quiet zone is designed to be
10X [Q (L) = 10X, Q (R) = 10X]. The respective value of W in above calculations, thereby, should be
71X,
(91X + 15),
(118X + 15).
As to the barcode height of UPC-E, it is not necessary for customers to worry about setting requirement. Our UPC-E barcode generation components will automatically set image height based on GS1 specification. Certainly, customers can adjust image height through Top or Bottom Margin setting.
Three Situations for Setting UPC-E Barcode Size in C#
Barcode size setting in C# UPC-E Generator may have three situations.
Situation 1:
If you need a UPC-E barcode with a minimum X, please do as below:
- Set the data to be encoded.
- Set the minimum value of X.
- Set the AutoResize option to be false.
- Customize other properties.
Eg1. You may set in C# generator:
upce. Data = "0612895";
upce.X = 3;
upce.AutoResize = false;
Other properties: default;
The generated UPC-E barcode is like:
If the barcode is UPC-E Two/Five-digit Add-On, you should select the barcode type (UPCE_2/UPCE_5). Then, set the supplement data. For example, you set:
upce.Type = BarcodeType.UPCE_5;
upce.Data = "0612895";
upce.SupData = "92012";
upce.X = 3;
upce.AutoResize = false;
Other properties: default;
The generated UPC-E barcode is like:
Situation 2:
If you need a UPC-E barcode with a fixed barcode image width (W), and try to draw maximum barcode module (X) as possible, please do as below:
- Set the data to be encoded.
- Set the fixed value of barcode image width (W).
- Set the AutoResize option to be true.
- Customize other properties.
Eg2. You may set in C# UPC-E generator:
upce. Data = "0612895";
upce.BarcodeWidth = 310;
upce.AutoResize = true;
Other properties: default;
The created UPC-E barcode is:
In this UPC-E barcode image, the maximum bar module (X) is 4 pixel.
If the barcode is UPC-E Two/Five-digit Add-On, you should select the barcode type (UPCE_2/UPCE_5), and then set the supplement data. For example, you set:
upce.Type = BarcodeType.UPCE_2;
upce.Data = "0612895";
upce.SupData = "25";
upce.BarcodeWidth = 213;
upce.AutoResize = true;
Other properties: default;
The created UPC-E barcode:
Now, the maximum value of bar module (X) is 2 pixel.
Situation 3:
If you need a UPC-E barcode with minimum X and fixed barcode image width (W), please do as below:
- Set the data to be encoded.
- Set the values of minimum X and barcode image width (W).
- Set the AutoResize option to be false.
- Customize other properties.
Eg3. You may set in C# UPC-E generator:
upce. Data = "0612895";
upce.X = 4;
upce.BarcodeWidth = 328;
upce.AutoResize = true;
Other properties: default;
The created UPC-E barcode is like:
Note that, in GS1 specification, once you have set bar module (X) value, there will be a minimum barcode image width.
- UPC-E without Add-On, W = 67X.
- UPC-E+ 2, W = 92 X.
- UPC-E+5, W = 118X.
Our UPC-E barcode generators will automatically set the value of each quiet zone to be
10X [Q (L) = 10X, Q (R) = 10X]), compatible with GS1 specification. So, the respective value of W in above calculations should be
71X,
(91X + 15),
(118X + 15).
In this case, if your BarcodeWidth value is less than the minimum barcode width, the barcode generator will reset BarcodeWidth value to the minimum barcode width value.
For instance, you set:
upce. Data = "0612895";
upce.X = 4;
upce.BarcodeWidth = 262;
upce.AutoResize = false;
- Then, W min = 71X = 284 pixel
- If the barcode has a Two-digit Add-On, W min = (91 X + 15) = 379 pixel.
- If the barcode has a Five-digit Add-On, W min = (118X + 15) = 487 pixel.
Now your BarcodeWidth setting is 262 pixel, which is less than the minimum barcode width (284 pixel), the generated UPC-E barcode is like below.
If your BarcodeWidth setting is 306 pixel, which is larger than the minimum barcode width (284 pixel), the generated UPC-E barcode is like below. And extra 22 pixel space will be appended to the left and right side of barcode image.