Setting UPC-A Barcode Size in C#




How to generate, print barcode using .NET, Java sdk library control with example project source code free download:

Generating and Printing UPC-A Barcodes

OnBarcode has professional UPC-A barcode generation and recognization libraries for Java, .NET, Android, iOS developments and some reporting applications.

UPC-A Structure

A typical UPC-A has the following structure:
An UPC-A barcode includes four areas:
  • Number System: It is one digit only which identifies the "type" of product, e.g., o: Regular UPC codes, 5: Coupons, 9: Reserved, etc.
  • Manufacturer Code: It has five digits in all, which is assigned by the UCC Council to each manufacturer or company that distributes goods with a printed UPC-A barcode. All products produced by a given company will use the same manufacturer code.
  • Product Code: It includes five digits, which is a unique code assigned by the manufacture. And manufacturers can assign their product codes randomly as long as all of their products have different codes.
  • Check Digit: It is an additional digit used to verify the accuracy of the data encoded. And the checksum digit can be computed base on the rest digits of the barcode.

Structure of UPC-A

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



Setting UPC-A Barcode Size in C#

Basic information you should know

GS1 specification defines the barcode width of UPC-A (W). Measured in pixel, it can be calculated as below.
  • UPC-A barcode with no Add-On,

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

  • UPC-A Two-digit Add-On, W = 138X.
  • UPC-A Supplement 5, W = 165X.

Our UPC-A barcode generators set automatically the value of each quiet zone 10X [Q (L) = 10X, Q (R) = 10X]. Thus, the respective value of W in above calculations should be 115X, (135X + 15), (162X + 15).

As to UPC-A barcode height, it is not necessary for customers to worry about the setting requirements. Our UPC-A barcode generating components will automatically set image height based on GS1 specification. Customers, meanwhile, can change image height by setting Top or Bottom Margin.


Three Situations for Setting UPC-A Barcode Size in C#

Barcode size setting in C# UPC-A Generator may have three situations.

Situation 1:

If you need to create a UPC-A barcode with a minimum X, please do as follows:
  • Set the data to be encoded.
  • Set the minimum value of X.
  • Set the AutoResize option false.
  • Customize other properties.
Eg1. In C# UPC-A barcode generator, you may set:
upca. Data = "04124537965";
upca.X = 3;
upca.AutoResize = false;
Other properties: default;
You will create a UPC-A barcode like below:

If the barcode is UPC-A Supplement 2 or 5, you need to choose the barcode type (UPCA_2/UPCA_5) and then set the supplement data. For example, you set in C# generator:

upca.Type = BarcodeType.UPCA_2;
upca.Data = "04124537965";
upca.SupData = "34";
upca.X = 3;
upca.AutoResize = false;
Other properties: default;
You will obtain a UPC-A barcode:


Situation 2:

If you need to create a UPC-A 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 true.
  • Customize other properties.
Eg2. In C# UPC-A barcode generator, you may set:
upca. Data = "04124537965";
upca.BarcodeWidth = 190;
upca.AutoResize = true;
Other properties: default;
You will create a UPC-A barcode:

In this UPC-A image, the bar module (X) is 1 pixel, which is the maximum bar module.

If the barcode is UPC-A Supplement 2 or 5, you should choose the barcode type (UPCA_2/UPCA_5) and then set the supplement data. For instance, you set in C# generator:

upca.Type = BarcodeType.UPCA_5;
upca.Data = "04124537965";
upca.SupData = "65432";
upca.BarcodeWidth = 190;
upca.AutoResize = true;
Other properties: default;
You will obtain a UPC-A barcode:

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


Situation 3:

If you need to create a UPC-A barcode with minimum X and fixed barcode image width (W), please do as follows.
  • 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. In C# UPC-A barcode generator, you may set:
upca. Data = "04124537965";
upca.X = 2;
upca.BarcodeWidth = 270;
upca.AutoResize = true;
Other properties: default;
You will create a UPC-A barcode:


Note that, in GS1 specification, there will be a minimum barcode image width as long as you set bar module (X) value.
  • UPC-A barcode with no supplement data, W = 113X.
  • UPC-A Supplement 2, W = 138 X.
  • UPC-A Supplement 5, W = 165X.
Our UPC-A barcode generation libraries will set the value of each quiet zone 10X [Q (L) = 10X, Q (R) = 10X])which is compatible with GS1 specification. In this case, 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 in C# UPC-A generator:

upca. Data = "04124537965";
upca.X = 3;
upca.BarcodeWidth = 270;
upca.AutoResize = false;
  • Then, W min = 115X = 345 pixel
  • If the barcode has a Two-digit Add-On, W min = (135 X + 15) = 420 pixel.
  • If the barcode has a Five-digit Add-On, W min = (162X + 15) = 501 pixel.
Now your BarcodeWidth setting is 270 pixel, which is less than the minimum barcode width (345 pixel), the created UPC-A barcode image is like below.


If your BarcodeWidth setting is 385 pixel, which is larger than the minimum barcode width (345 pixel), the created UPC-A barcode image will be like below. And extra 40 pixel space will be added 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.