How to create, print barcode image using C#.NET

How to generate, print linear, 2d barcode label images in C#, Windows application, WPF with free C#.NET source code

Create, Print barcode labels in C# ASP.NET Web, Windows application with free C# source code project

In this C# tutorial, you learn how to generate barcode images in ASP.NET web and Windows applications using C#.

  • Support .NET Core and .NET Framework
  • ASP.NET Web Forms
  • Web streaming in IIS
  • ASP.NET C# class
  • Barcode special character encoding
  • International character encoding
  • GS1 data encoding
  • Multiple barcodes generations for one data message

How to create linear, 2d barcodes in ASP.NET and Windows application using C#

  1. Download .NET Barcode Generator Suite
  2. Install C# library to create barcodes in .NET Projects
  3. Step by Step Tutorial

  • Generate linear, 2d barcode image label in C#.NET Class & console application
  • Create barcode images using C# in ASP.NET web forms, aspx web page, MVC web applications
  • Encode, print barcode images in C#.NET Windows Forms, WPF application
  • Print barcode in Reporting Services & Crystal Reports document
  • Support .NET 7, .NET 6, .NET 5, .NET Core 3.1, .NET Core 2.1
  • Support .NET Framework 4.x, 3.x, and 2.0
  • Generate linear, 2d barcode image label in C#.NET Class & console application
  • Generate, print bar code images to Jpeg, Gif, Tiff, Bitmap formats
  • Create, print barcode image with transparent background in PNG image labels
  • Completely developed in C#.NET, compatible with .net framework 2.0 and later versions, with free C# example source code
  • Generating 2d (matrix) barcode images, including QR Code in C#, PDF-417 in C#, Data Matrix in C#.
  • Creating linear (1d) barcode images, including Code 39 in C#, Code 128 in C#, EAN-8 in C#, EAN-13 in C#, UPC-A in C#, UPC-E in C#, GS1-128 in C#, OneCode in C#, Interleaved 2 of 5 in C#
  • Mature C#.NET barcode generating component control

Generating barcodes in C#.NET is an easy task with OnBarcode .NET Barcode Generator Components. OnBarcode provides various barcode libraries and controls for generating barcodes using Microsoft Visual C#.NET on ASP.NET, C# Class, Windows software, Console applications, and .NET Reporting projects. You can also use our .NET Barcode Reader SDK to read and scan barcodes in C#.
This article helps you to choose the right barcode generation component for integration in your C# applications.

C# Barcode Scanners

Compare Three .NET Barcode Generator components in different C#.NET development environments


ASP.NET Barcode Generator

  • Generate barcodes in C#.NET class
  • Generate barcodes in C# console applications
  • Generate barcodes in C# Web Forms projects

WinForms Barcode Generator

  • Generate barcodes in C#.NET class
  • Generate barcodes in C# console applications
  • Generate barcodes in C# Windows Forms projects

.NET Barcode Suite

  • Generate barcodes in C#.NET class
  • Generate barcodes in C# console applications
  • Generate barcodes in C# Web Forms projects
  • Generate barcodes in C# Windows Forms projects
  • Generate barcodes in C# Reporting Service 2005 & 2008 projects

C#.NET Barcode Generator Quick Start


1. How to install .NET Barcode Generator Control to your Visual C# project?

Add OnBarcode.Barcode.WinForms.dll or OnBarcode.Barcode.ASPNET.dll to C# project reference.

2. How to create linear barcodes in C# class?

    // Create linear barcode object
    Linear barcode = new Linear();
    // Set barcode symbology type to Code-39
    barcode.Type = BarcodeType.CODE39;
    // Set barcode data to encode
    barcode.Data = "0123456789";
    // Set barcode bar width (X dimension) in pixel
    barcode.X = 1;
    // Set barcode bar height (Y dimension) in pixel
    barcode.Y = 60;
    // Draw & print generated barcode to png image file

Barcode Code-39

3. How to draw & print QR-Code in C# class?

    // Create QRCode object
    QRCode qrCode = new QRCode();
    // Set QR Code data to encode
    qrCode.Data = "VB.NET QRCode";
    // Set QRCode data mode (QR-Code Barcode Settings)
    qrCode.DataMode = QRCodeDataMode.Auto;
    // Draw & print generated QR Code to jpeg image file
    qrCode.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

4. How to create & print Data Matrix in C# class?

    DataMatrix datamatrix = new DataMatrix();
    // Create Data Matrix object
    datamatrix.Data = "VB.NET DataMatrix";
    // Set Data Matrix data to encode
    datamatrix.DataMode = DataMatrixDataMode.ASCII;
    // Set the data mode (Data Matrix Barcode Settings)
    // Draw and print created Data Matrix to gif image file
    datamatrix.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;

5. How to create & print PDF-417 in C# class?

    // Create PDF417 object
    PDF417 pdf417 = new PDF417();
    // Set Data Matrix data to encode
    pdf417.Data = "PDF-417";
    // Set PDF-417 data mode (PDF-417 Barcode Settings)
    pdf417.DataMode = PDF417DataMode.Auto;
    // Set PDF-417 number of rows
    pdf417.RowCount = 3;
    // Set PDF-417 number of columns
    pdf417.ColumnCount = 5;
    // Draw and print generated PDF417 to gif image file
    pdf417.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;

6. In C# Barcode Generator, how to print & encode barcodes to GIF, JPEG, PNG & BMP?

    // Create linear barcode object
    Linear barcode = new Linear();
    // Set barcode symbology type to Code-39
    barcode.Type = OnBarcode.Barcode.BarcodeType.CODE39;
    // Set barcode data to encode
    barcode.Data = "0123456789";
    // Encode barcodes to other image format, by change file extension
    barcode.Format = System.Drawing.Imaging.ImageFormat.Gif;

C#.NET Barcode Generation Guides & Tutorials for Each Barcode


Barcode Control for C#.NET - Bar Code Type Generation

How to encode, create non-printable chars in barcode images using c#

Some barcode types support encoding full ASCII characters. However some special characters are impossible to be inserted to a string directly, such as char 'CR' (Carriage Return).

List of barcodes encoding full ASCII characters
  • Code 39 full ASCII mode
  • Code 128
  • Data Matrix
  • PDF417
  • QR Code
In C# barcode generator library, it provides a solution for inputting these non-printable characters.

Here is an example to encode char 'CR' (Carriage Return).
  1. Set property ProcessTilde to true.
  2. Convert non-printable char to '~ddd' format. Here ddd is the char ASCII Integer code. 'CR' should be converted to '~013'.
  3. Set property Data to '~013'
Here is the C# example source code:
            Linear code128 = new Linear();

            // encode non printable char '[CR]', between 'a' and 'b'
            code128.Data = "a~013bc";
            // Barcode symbology type. Code 128 supports types: CODE128, CODE128A, CODE128B, CODE128C.
            code128.Type = BarcodeType.CODE128;

            code128.ProcessTilde = true;

How to encode, print GS1 data in barcodes using c#

The GS1 system originated in the United States and was established in 1973 by the Uniform Product Code Council, known until recently as the Uniform Code Council, Inc. (UCC) and since 2005 as GS1 US.

The following barcode symbologes support GS1 data encoding:

  1. EAN/UPC: UPC-A, UPC-E, EAN-13, and EAN-8 barcodes, and the two- and five-digit add-on symbols
  2. ITF-14
  3. GS1-128 (EAN-128)
  4. GS1 DataBar
  5. Composite Component symbols do not exist in isolation. The primary identification number is always encoded in the linear symbol and supplementary GS1 Application Identifier element strings are encoded in the two-dimensional (2D) component where they take up less space
  6. Data Matrix
  7. GS1 QR Code

How to encode, print non-English chars (such as Thai, Arabic) in barcode images using c# in application

Most of the barcode types do not support encoding international text (such as Thai, Arabic) directly. To encode these characters, some 2d barcode symbologies (Data Matrix, PDF417, QR Code) provide solutions for you.

2D barcodes provide two methods for you to encode international text.
  1. Convert international characters to byte array using UTF-8 encoding, and encode byte array data in 2d barcodes in byte data mode.
  2. Use 2D barcode ECI feature to encode international characters

How to split a data file into more than one barcode symbols in C#

PDF417, Data Matrix, QR Code provide a mechanism for the data in a file to be split into blocks and be represented in more than one barcode symbol.

In PDF417, it is named Macro PDF417. In Data Matrix and QR Code, it is called Structure Append.

Each barocde symbol shall contain additional control information to enable the original data file to be properly reconstructed, irrespective of the sequence in which the individual barcode symbols are scanned and decoded.

2D barcodes Data Matrix, PDF-417, QR Code support above feature. Check each barcode symbology guide page for details.

OnBarcode is a market-leading provider of barcode imaging 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 comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. 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 © . All rights reserved.