Setting EAN-8 Barcode Size in C#
Adjusting EAN-8 Barcode Size in C#
In order to help developers understand how to set EAN-8 barcode size in C#, OnBarcode gives some examples as bellow.
Therefore, developers can easily control the barcode size with our EAN-8 Generators:
- Windows EAN-8 Generator Software, generating & pringting EAN-8 barcodes on any PC
- .NET EAN-8 Generator SDK, creating & drawing EAN-8 images in .NET
- C# EAN-8 Generation Component, generating & drawing EAN-8 in C#.NET projects
- ASP.NET EAN-8 Generation Component, creating & printing EAN-8 in ASP.NET
- VB.NET EAN-8 Generation Component, encoding & drawing EAN-8 barcodes in VB.NET.
- Android EAN-8 Generator Library, producing & printing EAN-8 in Android Projects
- BIRT EAN-8 Generator Library, generating & drawing EAN-8 in BIRT Reports
- Java EAN-8 Generator Library, creating, drawing & printing EAN-8 images in Java applications
- Reporting Service EAN-8 Generator Library, generating & printing EAN-8 in SQL Server Reporting Service (2005/2008)
How to generate, print barcode using .NET, Java sdk library control with example project source code free download:
Structure of EAN-8
- W : the width of EAN-8 barcode image, including quiet zones.
- X : the width of EAN-8 narrowest bar; X min = 1 pixel.
- C : the number of EAN-8 encoded data characters, including the check digit; C =8.
- Q : the width of the quiet zone; Q > = 7X; Q (L) = 7X, Q (R) = 7X.
Setting EAN-8 Barcode Size in C#
Basic information you should know
In GS1 specification, EAN-8 barcode width, W (measured in pixel), can be computed as below.
- EAN-8 barcode with no Add-On barcode:
W min = ( C * 7 + 11 ) X + 2Q       // C = 8, Q (L) = 7X, Q (R) = 7X.
= ( 8 * 7 + 11 ) X + 7X + 7X
= 67X + 14X
= 81X
- EAN-8 Two-digit Add-On: W = 106 X.
- EAN-8 Five-digit Add-On: W = 133X.
Note that, our EAN-8 barcode generators automatically set the value of each quiet zone
10X [Q (L) = 10X, Q (R) = 10X], then the respective value of W in above calculation should be
87X,
(107X + 15),
(134X + 15).
As for EAN-8 barcode height, our generators will automatically adjust it in accordance with GS1 specification. Meanwhile, it is user-defined as well, and customers may set it through Top and Bottom Margin settings.
Three Situations for EAN-8 Barcode Size Setting in C#
Setting barcode size in C# EAN-8 Barcode Generator may have three situations.
Situation 1:
To create an EAN-8 barcode with a minimum X, please do this:
- Set the data to be encoded.
- Set the minimum value of X.
- Set the AutoResize option false.
- Customize other properties.
Eg1. You may set in C# EAN-8 barcode generator like this:
ean8.Data = "1234567";
ean8.X = 3;
ean8.AutoResize = false;
Other properties: default;
The created EAN-8 barcode image is:
If a Two-digit or Five-digit Add-On barcode is added to EAN-8 barcode, you are supposed to select the barcode type (EAN8_2/_5) firstly, and then set the supplement data. For example, you may set:
ean8.Type = BarcodeType.EAN8_2;
ean8.Data = "1234567";
ean8.SupData = "89";
ean8.X = 3;
ean8.AutoResize = false;
Other properties: default;
You will generate an EAN-8 barcode:
Situation 2:
To create an EAN-8 barcode with a fixed barcode image width (W), and need to draw maximum barcode module (X) as possible, please do this:
- Set the data to be encoded.
- Set the fixed value of barcode image width (W).
- Set the AutoResize option true.
- Customize other properties.
Eg2. You may set in C# EAN-8 barcode generator like this:
ean8.Data = "1234567";
ean8.BarcodeWidth = 180;
ean8.AutoResize = ture;
Other properties: default;
The created EAN-8 barcode image is:
In the above EAN-8 barcode image, the maximum bar module (X) is 2 pixel.
If a Two-digit or Five-digit Add-On barcode is appended to EAN-8 barcode, you need to choose the barcode type (EAN8_2/_5) firstly, and then set the supplement data. For instance, you may set:
ean8.Type = BarcodeType.EAN8_5;
ean8.Data = "1234567";
ean8.SupData = "89012";
ean8.BarcodeWidth = 180;
ean8.AutoResize = true;
Other properties: default;
You will generate an EAN-8 barcode:
Now, the maximum value of bar module (X) is 1 pixel.
Situation 3:
To create an EAN-8 barcode with minimum X and fixed barcode image width (W), please do this.
- Set the data to be encoded.
- Set the values of minimum X and barcode image width (W).
- Set the AutoResize option false.
- Customize other properties.
Eg3. You may set in C# EAN-8 barcode generator like this:
ean8.Data = "1234567";
ean8.X = 2;
ean8.BarcodeWidth = 220;
ean8.AutoResize = false;
Other properties: default;
The created EAN-8 barcode image is:
Note that, GS1 specification indicates that there will be a minimum barcode image width as long as you set bar module (X) value.
- EAN-8 barcode without supplement data, W = 81X.
- EAN-8 Supplement 2, W = 106X.
- EAN-8 Supplement 5, W = 133X.
However, our EAN-8 barcode generation libraries automatically set the value of each quiet zone
10X [Q (L) = 10X, Q (R) = 10X]). In this case, the respective value of W in above calculation should be
87X,
(107X + 15),
(134X + 15).
Thereby, if your BarcodeWidth value is less than the minimum barcode width, the barcode generator component will reset BarcodeWidth value to the minimum barcode width value.
For instance, you set:
ean8.X = 3;
ean8.BarcodeWidth = 220;
ean8.AutoResize = false;
Other properties: default;
- Then, W min = 87X = 261 pixel
- If the barcode is an EAN-8 Two-digit Add-On, W min = (107X + 15) = 336 pixel.
- If the barcode is an EAN-8 Five-digit Add-On, W min = (134X + 15) = 417 pixel.
Now your BarcodeWidth setting is 220 pixel, which is less than the minimum barcode width (261 pixel), the created EAN-8 image is like this.
If your BarcodeWidth setting is 291 pixel, which is larger than the minimum barcode width (261 pixel), the created EAN-8 barcode image will be like below. And extra 30 pixel space will be added to the left and right side of barcode image.