Barcodes are used to visually represent the data in a machine-readable form. Most often, barcodes appear to be a means of a product’s identification. Various types of barcodes are used in different scenarios such as Code128, QR, Datamatrix, Aztec, etc. In this article, you will learn how to generate the barcodes in C#. Furthermore, you will see how to customize the appearance of a barcode.
- C# Barcode Generator API
- How to Generate a Barcode using C#
- How to Generate QR Barcode using C#
- Customize the Appearance of a Barcode in C#
- Add Caption in Barcode using C#
C# Barcode API - Free Download
Aspose.BarCode for .NET is a powerful barcode generator and scanner API. It lets you generate and read a wide range of barcode symbologies, including but not limited to:
- Code128
- Code11
- Code39
- QR
- Datamatrix
- EAN13
- EAN8
- ITF14
- PDF417
- and more.
You can download the API for free or get it installed within your .NET application using NuGet.
PM> Install-Package Aspose.BarCode
How to Generate a Barcode using C#
The following are the steps to generate a barcode using Aspose.BarCode for .NET.
- First, create an object of BarcodeGenerator class and specify the barcode’s type and text in its constructor.
- Set barcode’s features such as resolution and etc.
- Finally, generate barcode using BarcodeGenerator.Save(String) method.
The following code sample shows how to generate a barcode using C#.
How to Generate a QR Barcode using C#
You can generate other types of barcodes in a similar way. For the demonstration, let’s generate a QR barcode. The following are the steps to generate a QR barcode.
- Create an object of BarcodeGenerator class and specify the barcode’s type as EncodeTypes.QR.
- Generate barcode using BarcodeGenerator.Save(String) method.
The following code sample shows how to generate a QR barcode using C#.
Customize the Appearance of a Barcode in C#
You can also customize the appearance of the barcode. For example, you can change its font, forecolor, background color, text color, and etc. The following are the steps to customize a barcode using Aspose.BarCode for .NET.
- First, create an instance of BarcodeGenerator class.
- Set the barcode’s appearance using BarcodeGenerator.Parameters properties i.e. BarcodeGenerator.Parameters.BackColor.
- Finally, generate barcode using BarcodeGenerator.Save(String) method.
The following code sample shows how to generate a customized Aztec barcode using C#.
Add Caption in Barcodes using C#
You might have seen barcodes with a caption above or below the barcode image. These captions can be used to display additional information about the barcode itself. Aspose.BarCode for .NET also allows you to add a caption below, above, or on both sides of the barcode. The following are the steps to add a caption.
- First, create an object of BarcodeGenerator class.
- Set the barcode’s text and type in the constructor of BarcodeGenerator.
- Set caption using CaptionAbove or CaptionBelow properties.
- Finally, save the barcode using BarcodeGenerator.Save(String) method.
The following code sample shows how to add caption in a barcode using C#.
Conclusion
In this article, you have learned how to generate barcodes programmatically using C#. In addition, you have seen how to customize a barcode by modifying its appearance. You can explore more about the C# barcode generator API using documentation.