Setting EAN-13 Barcode Size in C#

C# EAN-13 Barcode Size Setting

OnBarcode offers explanation of how to set EAN-13 barcode size in C# with our Barcode Generators for EAN-13. Definitely, users are entitled to control EAN-13 image size using the products below.

EAN-13 Structure

  • W : the width of EAN-13 barcode image, including quiet zones.
  • X : the width of EAN-13 narrowest bar; X min = 1 pixel.
  • C : the number of EAN-13 encoded data characters, including the check digit; C =12.
  • Q : the width of the quiet zone; Q > = 7X; Q (L) = 11X, Q (R) = 7X.



Setting EAN-13 Barcode Size in C#

Basic information you should know

According to GS1 specification, the barcode width of EAN-13, W (measured in pixel), is easy to be calculated.
  • EAN-13 barcode without supplement data:

W = ( C * 7 + 11 ) X + 2Q       // C = 12, Q (L) = 11X, Q (R) = 7X.
W min = 113X

  • If EAN-13 barcode needs a Two-digit Add-On, the whole barcode image width including the minimum quiet zones should be 138X. W min = 138 pixel.
  • If EAN-13 barcode needs a Five-digit Add-On, the whole barcode image width including the minimum quiet zones should be 165X. W min = 165 pixel.

In Our EAN-13 generators, the value of each quiet zone is designed to be 10X [Q (L) = 10X, Q (R) = 10X].Therefore, the respective value of W in above calculation should be 115X, (135X + 15), (162X + 15).

The height of EAN-13 barcode should conform to GS1 specification (25.9 millimeters). To make things easier, our EAN-13 barcode generators may automatically control the image height according to the specification. Certainly, the image height is user-defined and customers can adjust the barcode height through Top and Bottom Margin settings.


Three Situations for Setting EAN-13 Barcode Size in C#

Barcode size setting in C# EAN-13 Generator may have three situations.

Situation 1:

If you want to generate an EAN-13 barcode with a minimum X, please do this:
  • Set the data to be encoded.
  • Set the minimum value of X.
  • Set the AutoResize option to be false.
  • Customize other properties.
Eg1. In C# EAN-13 generator, you set:
ean13.Data = "987654321098";
ean13.X = 2;
ean13.AutoResize = false;
Other properties: default;
The generated EAN-13 barcode image is:

If EAN-13 needs a supplement data (2 or 5 digits), you should firstly choose the barcode type (EAN13_2/EAN_5), then set the supplement data. For instance, you set:

ean13.Type = BarcodeType.EAN13_2;
ean13.Data = "987654321098";
ean13.SupData = "76";
ean13.X = 2;
ean13.AutoResize = false;
Other properties: default;
You will get an EAN-13 barcode:


Situation 2:

If you want to generate an EAN-13 barcode with a fixed barcode image width (W), and try 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 to be true.
  • Customize other properties.
Eg2. In C# EAN-13 generator, you set:
ean13.Data = "987654321098";
ean13.BarcodeWidth = 300;
ean13.AutoResize = ture;
Other properties: default;
The generated EAN-13 barcode image is:

In the above EAN-13 image, the bar module (X) is 2 pixel, which is the maximum bar module.

If EAN-13 has a supplement data (2 or 5 digits), please choose the barcode type (EAN13_2/EAN_5), and then set the supplement data. For example, you set:

ean13.Type = BarcodeType.EAN13_5;
ean13.Data = "987654321098";
ean13.SupData = "76543";
ean13.BarcodeWidth = 300;
ean13.AutoResize = ture;
Other properties: default;
You will get an EAN-13 barcode:

Now, the maximum value of bar module (X) is 1 pixel.


Situation 3:

If you want to generate an EAN-13 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 to be false.
  • Customize other properties.
Eg3. In C# EAN-13 generator, you set:
ean13.Data = "987654321098";
ean13.X = 3;
ean13.BarcodeWidth = 350;
ean13.AutoResize = false;
Other properties: default;
The generated EAN-13 barcode image is:


Note that, once you have set bar module (X) value, there will be a minimum barcode image width defined by GS1 specification.
  • EAN-13 barcode without supplement data, W = 113X.
  • EAN-13 barcode with a Two-digit Add-On, W = 138 X.
  • EAN-13 barcode with a Five-digit Add-On, W = 165X.
In Our EAN-13 generators, the value of each quiet zone is default by 10X [Q (L) = 10X, Q (R) = 10X]), compatible with GS1 specification. And the respective value of W in above calculations should be 115X, (135X + 15), (162X + 15).

So 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 example, you set:

ean13.X = 4;
ean13.BarcodeWidth = 350;
ean13.AutoResize = false;
Other properties: default;
  • Then, W min = 115X = 460 pixel
  • If the barcode adds a Two-digit Add-On, W min = (135 X + 15) = 555 pixel.
  • If the barcode adds a Five-digit Add-On, W min = (162X + 15) = 663 pixel.
Now your BarcodeWidth setting is 350 pixel, which is less than the minimum barcode width (460 pixel), the generated EAN-13 image is like this.


If your BarcodeWidth setting is 480 pixel, which is larger than the minimum barcode width (460 pixel), the generated EAN-13 barcode image will be like below. And extra 20 pixel space has been appended to the left and right side of barcode image.






OnBarcode is a market-leading provider of barcode generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides high quality tutorials and guides for various linear, 2d barcode information, such as C# Barcode, QR Code C#, QR Code VB.NET, QR Code ASP.NET, QR Code .NET, ASP.NET Barcode. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.