Using C# Barcode Generator
How to create barcodes using c# in asp.net mvc, windows application
Generate, create, print linear, 2d barcode image labels in c# asp.net, windows applications.
Barcode for .NET Suite > Generate Barcode in C#


  • Developed completely in C# with full integration into MS .NET Framework & many Windows systems
  • Compatible with ISO/IEC & GS1 symbology specifications to print scannable barcode images
  • Using Barcode Control Library to add barcodes in ASP.NET websites/webservice, WinForms, etc
  • Easy to create 1D and matrix barcode images in Visual C#.NET & console applications
  • Support multiple high quality linear barcodes generation, including alphanumeric barcodes
  • Support major bi-dimensional barcode symbologies, including Data Matrix, QR Code and PDF-417
  • Available for saving barcode pictures with different formats, like jpg, png, tiff, bitmap, etc
  • Reliable C# barcode generator component to print barcode for all scanners and printers
KA.Barcode for .NET Suite supports generating barcode images for ASP.NET Web, .NET WinForms, Crystal Reports, and RDLC Report applications with C#.NET programming. It allows creating more than 20 barcode types including linear and matrix barcodes:
Linear Barcodes: Codabar, Code 39, Code 128, EAN-128, EAN-13, UPC-A, EAN-8, UPC-E, Code11, Identcode, Interleaved 2 of 5, MSI Plessey, Intelligent Mail, Code 93, Leitcode, Planet, Postnet, ISSN, ISBN, Code 2 of 5, ITF-14, RM4SCC.
Matrix Barcodes: QR Code, Data Matrix, PDF-417.

Download KA.Barcode for .NET Suite Trial Version

Perpetual Evaluation
We offer perpectual evaluation/trial version of this barcode generator library.
Restrictions of Evaluation
If you want to use generated barcodes for commercial application, you need to buy our developer licenses for the barcodes generated by evaluation version will include a "KA Barcode" watermark.

How to Install KA.Barcode for .NET Suite

Unzip the trial freeware package, and you'll find "KeepAutomation.Barcode.Windows.dll" and "KeepAutomation.Barcode.Web.dll" in the package. Add the barcode dll(s) to your Visual Studio reference. After that, copy sample code into your project to insert barcode pictures or images according to tutorial.
  • Create a new project and select "Add Reference...", then click "Browse..." to locate "KeepAutomation.Barcode.Windows.dll" or "KeepAutomation.Barcode.Web.dll"
  • Then click "OK". Immediately, you'll find "KeepAutomation.Barcode.Windows" or "KeepAutomation.Barcode.Web" in the References




Barcode Data Encoding in C#

Numeric, ASCII printable characters

Generating barcodes with printable characters is an easy job using C# programming.
  • Create a new BarCode object
  • Specify the barcode type with property Symbology
  • Provide the barcode encoding data to property CodeToEncode
  • Now you can encode the barcode and output the generated barcode to image file or image in byte array data in your C# code
            BarCode aBarcode = new BarCode();

            aBarcode.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto;

            aBarcode.CodeToEncode = "ABC-123-abc";

            aBarcode.generateBarcodeToImageFile(FileOutputPath + "barcode-printable-chars.png");




ASCII non-printable characters

Some barcode symbologies (such as Code 128, QR Code) support encoding full ASCII characters (128 chars), extended ASCII characters (total 256 chars). There are non-printable characters in ASCII and extended ASCII characters, such as char 'Carriage Return or '[CR]'.

To help encode non-printable ASCII chars in the C# code, C# barcode generator library provides a special method. You can encode those non-printable chars using their ASCII values.

In the C# code, use '~' + three digits to represent the non-printable char, the value of the three digits are the char ASCII value.

For example, char '[CR]' ASCII value is 13. To encode '[CR]' in Code 128, you can use the following data format

Here is a short demo code to show how to create barcode with non-printable characters encoded in C# source code.
  • Create a new BarCode object
  • Specify the barcode type with property "Symbology"
  • Set property TildeEnabled to true, which allows you to use "~ddd" ('~' followed by three digits) to represent a non-printable character in C#
  • Provide the barcode encoding data to property CodeToEncode
  • Generate the barcode image with non-printable character in C#
            BarCode aBarcode = new BarCode();

            aBarcode.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto;

            aBarcode.TildeEnabled = true;

            aBarcode.CodeToEncode = "A~013A";

            aBarcode.generateBarcodeToImageFile(FileOutputPath + "csharp-barcode-non-printable-chars.png");




If we enlarge the above barcode image, the character '[CR]' has been encoded in the Code 128 barcode. Howerver non-printable chars will not be displayed in the barcode HRI (barcode text area).

In the image below, the circled area are encoding bars for char '[CR]'.





Barcode Image & Color Settings using C#

C# barcode generator library provides options to customize the generated barcode image resolution for high/low resolution printers, image file format, bar/space colors.

The following C# source code show to how to encode and customize the QR Code barcode image and color settings.
  • Property DPI to setting image resolution in dots per inch. To print barcodes on high resolution printers, the generated barcode image resolution should be higher than the printer's.
  • Property ImageFormat to specify the encoded barcode image format. It supports BMP, PNG, JPEG, GIF, TIFF raster images.
  • Property ForeColor to set the barcode bar module color. The default color is black.
  • Property BackColor to set the barcode space module color. The default color is white.
            BarCode aBarcode = new BarCode();

            aBarcode.Symbology = KeepAutomation.Barcode.Symbology.QRCode;
            aBarcode.CodeToEncode = "QR Code";

            aBarcode.DPI = 900;
            aBarcode.ImageFormat = ImageFormat.Png;

            aBarcode.ForeColor = Color.Red;
            aBarcode.BackColor = Color.Blue;

            aBarcode.generateBarcodeToImageFile(FileOutputPath + "csharp-barcode-image-color-settings.png");


Here is the generated QR Code with customized image and colors' settings using above C# source codes.





Linear Barcode Text Label Settings using C#

Linear (1d) barcodes usually include HRI area (Human Readable Interpretation). C# barcode generator library allows you easily customize the rendered text below barcode symbology
  • Property DisplayText to show or hide HRI besides barcode.
  • Property DisplayChecksum to show or hide check digit character in the HRI
  • Property TextFont to set the HRI text font name, font style, font size
  • Property TextColor to set the text color
  • Property TextMargin to set the space between barcode symbology and barcode text




            BarCode aBarcode = new BarCode();

            aBarcode.Symbology = KeepAutomation.Barcode.Symbology.Code39ex;
            aBarcode.CodeToEncode = "ABC-123-abc";
            aBarcode.ChecksumEnabled = true;

            aBarcode.DisplayText = true;
            aBarcode.DisplayChecksum = true;
            aBarcode.TextFont = new Font("Arial", 14f, FontStyle.Regular);
            aBarcode.TextColor = Color.Red;
            aBarcode.TextMargin = 30;

            aBarcode.generateBarcodeToImageFile(FileOutputPath + "csharp-barcode-text-label-settings.png");

How to Generate Barcodes with C#.NET Class

KA.Barcode Generator SDK for C#.NET supports multiple C# methods to create barcodes and output to different C# objects. Here is the Visual C# sample code for you:
C# Sample code
     using KeepAutomation.Barcode.Bean;
BarCode barcode = new BarCode();
barcode.Symbology = KeepAutomation.Barcode.Symbology.Code39;
barcode.CodeToEncode = "111222333";
barcode.ChecksumEnabled = true;
barcode.X = 1;
barcode.Y = 50;
barcode.BarCodeWidth = 100;
barcode.BarCodeHeight = 70;
barcode.Orientation = KeepAutomation.Barcode.Orientation.Degree90;
barcode.BarcodeUnit = KeepAutomation.Barcode.BarcodeUnit.Pixel;
barcode.DPI = 72;
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;
barcode.generateBarcodeToImageFile("C://barcode-code39-csharp.gif");

/* Output barcode images to different objects
barcode.generateBarcodeToStream("Stream Object");
barcode.generateBarcodeToGraphics("Graphics Object");
barcode.generateBarcodeToGraphics("HttpResponse Object");
*/

How to Generate Barcodes for ASP.NET with C# Class

KeepAutomation barcode generator for .NET Suite allows users to create barcode images in Visual C# class library. Below are some C# sample codes for barcode generation in ASP.NET. Or you may view more details of barcode generation for ASP.NET.
  1. Open Visual Studio to create a web application project.
  2. Add our "KeepAutomation.Barcode.Web.dll" to your ASP.NET Web project reference.
  3. And then enter your C# class code by clicking "View Code" in "Default.aspx".
  4. Now, copy following sample code into "Default.aspx.cs".
  5. After that, run the project and you can find the generated barcode image.
C# Sample code
     using KeepAutomation.Barcode.Bean;

BarCode code39 = new BarCode();
code39.Symbology = KeepAutomation.Barcode.Symbology.Code39;
code39.CodeToEncode = "39393939";
code39.generateBarcodeToImageFile("C://code39.png");

How to Generate Barcodes in .NET WinForms with C# Class

Developers can also print linear and 2D barcode images in .NET Windows application using Visual C# codes. Please follow the tutorial below for barcoding. You can also view more detailed information of barcode generation in .NET WinForms.
  1. Start with Visual Studio, and create a Windows application project.
  2. Then add "KeepAutomation.Barcode.Windows.dll" to the Forms project reference.
  3. Drag and drop a button to the form and double click it for compiling C# barcode generation code
  4. Now, run this windows project and you can find the created barcode image.
C# Sample code
     using KeepAutomation.Barcode.Bean;

BarCode code128 = new BarCode();
code128.Symbology = KeepAutomation.Barcode.Symbology.CodeAuto;
code128.CodeToEncode = "128128128";
code128.generateBarcodeToImageFile("C://code128.png");
You can also refer to this barcode properties page to customize your barcode images.

How to Create Barcodes for Crystal Reports with C# Class

This C#.NET Barcode Generator also supports barcode printing in .NET Crystal Reports. Here is more information about C# barcode creation in Crystal Reports.

How to Create Barcodes for RDLC Reports with C# Class

.NET Developers can easily print high-quality barcode images in RDLC Local Reports using Visual C# programming. You can get details about C# barcode generation in RDLC Reports here.