|
- Barcode in C# >
- Barcode .NET >
- C#.NET Barcode Generator: Free C# example source code project to create, print linear, 2d barcode lables in C#.NET projects
How to create, print barcode image in C# ASP.NET, MVC,
Windows app?
How to generate linear, 2d barcode images in C# asp.net, WPF with C# source code
Create, Print barcode labels in C# ASP.NET Web, WinForms, WPF desktop 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#.
- Integrate C# barcode library into ASP.NET Core, ASP.NET Framework, MVC, web applications
- Integrate C# barcode library into .NET Core Winodws Forms, WPF, console Windows application
- Creating QR Code, Data Matrix, PDF-417 2d barcodes, also encoding Code 128, Code 39, GS1-128, EAN/UPC linear barcode formats
in C# applications
- Encode digits, alpha-numeric text into barcode, also encoding complex data such as non-printable chars, Unicode text, GS1, byte array data
- Easy to customize barcode dimension width and height, 1d barcode text labels and advanced image options
- Generate styled QR Code with detailed C# demo source code
How to create linear, 2d barcodes in ASP.NET and Windows application using C#
- 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
Download & install C# Barcode Generator library to .NET projects
 Top
Install through NuGet
For .NET Core (Class library, Console, Windows Forms, WPF) apps on Windows
> Install-Package OnBarcode.Barcode.Generator
For ASP.NET Core web apps on Windowss
> Install-Package OnBarcode.Barcode.Generator.AspNet.Core
For .NET Core (Class library) apps on non-Windows (Linux, MacOS, ...)
> Install-Package OnBarcode.Barcode.Generator.SkiaSharp
For ASP.NET Core web apps on non-Windows (Linux, MacOS, ...)
> Install-Package OnBarcode.Barcode.Generator.AspNet.Core.SkiaSharp
For ASP.NET Framework web application
> Install-Package OnBarcode.Barcode.Generator.AspNet.Framework
For Windows Forms, WPF, Console (.NET Framework) application
> Install-Package OnBarcode.Barcode.Generator.WinForms.Framework
Download Barcode Generator DLLs
OnBarcode C# Barcode Generator Suite SDK trial version is free to download. You can download it directly here:
Download C# Barcode Generator Suite SDK trial version
Install & Setup library on .NET projects
For .NET Core apps on Windows
- Add OnBarcode.Barcode.Common.dll and OnBarcode.Barcode.ASPNETCore.dll
(for ASP.NET Core web streaming only) from folder "{downloaded package}/dll/NetStandard2.0/" to .NET project reference.
- You need manually add System.Drawing.Common from "NuGet Package Manager" to .NET Core project reference.
For .NET Core apps on non-Windows (Linux, MacOS, ...)
- Add OnBarcode.Barcode.Common.Skia.dll and OnBarcode.Barcode.ASPNETCore.Skia.dll (for ASP.NET Core web streaming only) from folder "{downloaded package}/dll/NetStandard2.0/" to .NET project reference.
- You need manually add SkiaSharp from "NuGet Package Manager" to .NET Core project reference.
For .NET Framework 4.x applications
- Add OnBarcode.Barcode.ASPNET.dll or OnBarcode.Barcode.WinForms.dll from folder "{downloaded package}/dll/Net40/" to .NET project reference.
For .NET Framework 3.x or 2.x applications
- Add OnBarcode.Barcode.ASPNET.dll or OnBarcode.Barcode.WinForms.dll from folder "{downloaded package}/dll/Net20/" to .NET project reference.
We have provided step by step barcode library setup tutorials for .NET projects.
How to create barcodes in C# class using C# Barcode Generator library?
 Top
Using C# barcode library, you can easily create, customize the barcode and save to a hard-copy of the image file, or draw to memory for further processing.
Render a QR Code to an image file
Here we will see how to quickly generate a simple QR Code image file with 3 lines of C# code using OnBarcode C# Barcode Suite.
- Firstly, create a new QRCode object, which allows you to create a QR Code barcode image with customized settings.
- Set the QR Code encoding data as "QR Code"
- Call method drawBarcode() to create a new QR Code image file using C# code
QRCode barcode = new QRCode();
barcode.Data = "QR Code";
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//qrcode-quick-create.png");
Here is the QR Code generated using the above C# codes.
Using C# Barcode library, you can easily generate and customize barcode and output to raster (PNG, Bitmap, JPEG) and vector (SVG, EPS) images.
View more details here: Create barcode in PNG, BMP raster images and SVG, EPS vector images
Create a Code 128 barcode in Stream object
The following C# source code example shows how to quickly create a simple Code 128 barcode with digits and text content
using 4 lines of C# code in your .NET project.
- Create a new Linear object, which allows you to create any 1d/linear barcode type
- Set the barcode data as "ABC-123-abc"
- Set the barcode object's barcode type as "BarcodeType.CODE128"
- Create a new Stream object, which will store the Code 128 barcode image data
- Call method drawBarcode() to create a new Code 128 barcode and save the barcode to the Stream object
Linear barcode = new Linear();
barcode.Data = "ABC-123-abc";
barcode.Type = BarcodeType.CODE128;
Stream barcodeInStream = new MemoryStream();
barcode.drawBarcode(barcodeInStream);
Here is the Code 128 generated using the above C# codes.
Create a barcode, and draw to a Graphics object
You can also easily create a barcode and paint the barcode to an existing Graphics object.
Linear barcode = new Linear();
barcode.Data = "Code 128";
barcode.Type = BarcodeType.CODE128;
barcode.BarcodeWidth = 200;
barcode.BarcodeHeight = 150;
Bitmap bitmap = new Bitmap(200, 150);
Graphics barcodeInGraphics = Graphics.FromImage(bitmap);
barcode.drawBarcode(barcodeInGraphics);
bitmap.Save("C://Output//barcode-sample.png");
Create a barcode, draw barcode in byte array object in C#
You can also quickly create a barcode and encode the barcode data in a byte array object using C#.
Linear barcode = new Linear();
barcode.Data = "Code 128";
barcode.Type = BarcodeType.CODE128;
byte[] barcodeInBytes = barcode.drawBarcodeAsBytes();
C#.NET Barcode Generation Guides & Tutorials for Each Barcode
 Top
Barcode Control for C#.NET - Bar Code Type Generation
How to create barcode with various data formats using C#?
 Top
Barcode may need encode data with various data formats, such as
- Numeric digits (0-9)
- AlphaNumeric (0-9; Upper case letters, and some special characters)
- ASCII characters
- Extended ASCII characters
- Unicode text
- Some standards with specific requirements (Such as GS1 system)
- Byte data to store data in special formats (Such as store an image file into QR Code barcodes)
How to generate barcode with digits and printable text using c#?
You can easily use C# code to create barcode with simple data formats (such as digits, upper case, lower case letter,
and other printable characters from ASCII, extended ASCII character sets).
In the C# codes below, you can directly provide the printable characters to the barcode object Data property, and the C# barcode
generator library will automatically create the barcode from the input numeric text using C#.
Linear code128 = new Linear();
code128.Type = BarcodeType.CODE128;
code128.Data = "ABC-123-abc";
code128.drawBarcode("C://Projects//Barcode-OnBarcode//Output//code128-simple-data.png");
However you could also need generate QR Code or 1d barcodes from some special characters (such as non-printable characters, Unicode text), the C# barcode
generator library has provided C# API to support it.
How to encode non-printable chars in barcode images using asp.net c#?
Some barcode types support encoding full ASCII characters. However some special characters are impossible to
be entered using keyboard 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 an easy solution for encoding these non-printable characters.
Here is an example to encode char 'CR' (Carriage Return) in Code 128 barcode using C#.
- Set property ProcessTilde to true.
- Convert non-printable char to '~ddd' format. Here ddd is the char ASCII Integer code in 3-digit. 'CR' should be converted to '~013'.
- 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;
Note: the non-printable chars will not be displayed in the barcode text
How to encode, print GS1 data elements in barcodes using asp.net 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.
A simple GS1-128 barcode generation
The following C# source code example shows how to quickly create a simple GS1-128 barcode with two GS1 data elements.
- Create a new Linear object, which allows you to create any 1d/linear barcode type
- Set the barcode object's barcode type as "BarcodeType.EAN128"
- Set the barcode data as "(00)395123451234567895(01)09501101530003"
- Call method drawBarcode() to output the GS1-128 barcode to an image file
Linear barcode = new Linear();
barcode.Type = BarcodeType.EAN128;
barcode.Data = "(00)395123451234567895(01)09501101530003";
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//gs1-128-quick-create.png");
GS1 System supporting barcode formats
The following barcode symbologes support GS1 data encoding:
- EAN/UPC:
UPC-A,
UPC-E,
EAN-13, and
EAN-8 barcodes, and the two- and five-digit supplemental add-on symbols
- ITF-14
- GS1-128 (EAN-128)
- GS1 DataBar
- 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
- GS1 Data Matrix
- GS1 QR Code
How to encode Unicode text (such as Thai characters) in barcode using c# 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.
- Convert international characters to byte array using UTF-8 encoding, and encode byte array data in 2d barcodes in byte data mode.
- Use 2D barcode ECI feature to encode international characters
C# barcode generator SDK has implement these solutions for you. You can find the C# demo code in the following pages.
How to encode byte array data into barcode using c# code?
Most of 2d barcode symbologies such as QR Code, Data Matrix, PDF-417 do support byte array data encoding. Using C# barcode library, you can
easily create barcodes with byte array data encoded in your C# program.
- Set the barcode data mode to byte
- Enable property ProcessTilde to true. Now the C# barcode library can process byte array data
- Convert each byte to '~ddd' format. For example, a byte '80' will be converted to '~080'.
- Set property Data with the converted bytes combined in string
- Generate barcode with the bytes data encoded
QRCode barcode = new QRCode();
String message = "abc";
byte[] bytes = Encoding.UTF8.GetBytes(message);
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
sb.Append("~" + b.ToString().PadLeft(3, '0'));
barcode.DataMode = QRCodeDataMode.Byte;
barcode.ProcessTilde = true;
barcode.Data = sb.ToString();
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//qrcode-data-in-bytes.png");
How to create barcode with specified dimension width, height using C#?
 Top
You can easily create a QR Code barcode with specified image width and height in C# using barcode library.
- Set AutoResize to true. When the property is true, the barcode library will automatically draw the whole QR Code barcode on the specified area.
- Set BarcodeWidth to the value of printed barcode image width
- Set BarcodeHeight to the value of printed barcode image height
QRCode barcode = new QRCode();
barcode.Data = "QR Code";
barcode.AutoResize = true;
barcode.BarcodeWidth = 250;
barcode.BarcodeHeight = 250;
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//barcode-size.png");
How to customize 1d barcode text styles using C#?
 Top
Using C# barcode generator, you can easily apply the 1d barcode text (HRI) styles with the following property settings:
- Text font style. Property "TextFont" allows you to customize the text font family, size, and style using object Font.
- Text color. Property "TextColor" allows you to set the printed text color.
- Text space with the bar modules. Property "TextMargin" to set the space (in dpi) between barcode modules and the printed text label.
- Show or hide the text. Property "ShowText" to display or hide the barcode text.
- Show or hide the check sum character, if any. Property "ShowCheckSumChar" to display or hide the barcode text.
Barcode text font size, style, color settings using C#
The C# code and barcode image below explains how to customize the rendered barcode text using property "TextFont", "TextColor", and "TextMargin".
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE128;
barcode.Data = "ABC-123-abc";
barcode.TextFont = new Font("OCR-b", 9f, FontStyle.Regular);
barcode.TextColor = Color.Red;
barcode.TextMargin = 10;
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//barcode-text-styles.png");
Barcode text show or hidden using C#
You can easily hide the linear barcode printed text using property "ShowText" in your C# code.
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE128;
barcode.Data = "ABC-123-abc";
barcode.ShowText = false;
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//barcode-text-hidden.png");
Barcode check sum character show or hidden using C#
You can also choose to hide barcode check sum character in the printed barcode text using C# barcode generator library.
The following C# code will create a Code 39 barcode with check sum digit ('$') enabled and displayed in the barcode text using C# barcode generator.
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE128;
barcode.Data = "ABC-123-abc";
barcode.ShowText = false;
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//barcode-text-hidden.png");
Here we will add one line of code to hide the calculated barcode check sum digit. In the barcode image below the barcode still include checksum digit, but it is not displayed in the barcode text.
barcode.ShowCheckSumChar = false;
How to customize barcode image settings using C#?
 Top
Using C# barcode generator library, you can find that it is really easy to customize the barcode image format, settings in the C# application.
- Image resolution
- Image colors (support transparent background image)
- Output to multple raster image formats (JPEG, PNG, GIF, Bitmap, TIFF)
- Output to vector image formats (SVG & EPS)
Here we will create a simple QR Code with 300 dpi resolution, bar module in red color, space module in blue color using C# codes.
QRCode barcode = new QRCode();
barcode.Data = "QR Code";
barcode.Resolution = 300;
barcode.ForeColor = Color.Red;
barcode.BackColor = Color.Blue;
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//barcode-image-setting.png");
You can find more information here:
How to apply barcode image settings in C# using C# barcode generator library?
How to create customed QR Code with logo added using C#?
 Top
Sometimes you need add logo to generated QR Code for marketing, you can easily create customed QR Code with logo added using C# barcode generator.
The C# source code here will add a logo image to the center of the created QR Code. You just
set the property " Logo" and " LogoActualSize" to specify the logo image location and rendered size.
QRCode barcode = new QRCode();
barcode.Data = "https://www.facebook.com";
barcode.Logo = new System.Drawing.Bitmap("W://Projects//Test-Files//facebook_logo_2021.svg.png");
barcode.LogoActualSize = new System.Drawing.SizeF(600, 600);
barcode.UOM = UnitOfMeasure.INCH;
barcode.AutoResize = true;
barcode.BarcodeWidth = 3;
barcode.BarcodeHeight = 3;
barcode.Resolution = 900;
barcode.AutoResizePaddingTransparent = true;
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
barcode.drawBarcode("C://Projects//Barcode-OnBarcode//Output//barcode-styled-qrcode.png");
You can view more details about styled QR Code generation using C# barcode library here:
How to create styled QR Code using C#?
How to split a data file into more than one barcode symbols in C#
 Top
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.
|