Generate Barcode using C#

Barcodes play a crucial role in product identification, offering a visual representation of data that machines can effortlessly read. Various types of barcodes, such as Code128, QR, Datamatrix, and Aztec, are widely used across numerous industries. In this article, you will learn how to generate barcodes in C# and customize their designs using the powerful Aspose Plugin.

Table of Contents

C# Barcode API - Free Download

The Aspose.BarCode for .NET library is a comprehensive API for barcode generation and scanning. It enables you to create and read a wide range of barcode symbologies, including:

  • Code128
  • Code11
  • Code39
  • QR
  • Datamatrix
  • EAN13
  • EAN8
  • ITF14
  • PDF417
  • and many more.

You can download the API for free or install it directly in your .NET application using NuGet:

PM> Install-Package Aspose.Barcode

How to Generate a Barcode using C#

Creating a barcode with the Aspose Plugin is straightforward and efficient. Follow these steps to generate a barcode:

  1. Create an instance of the BarcodeGenerator class, specifying the barcode type and text in the constructor.
  2. Configure the barcode’s features, such as resolution and size.
  3. Generate the barcode using the BarcodeGenerator.Save(String) method.

Here’s a code sample demonstrating how to generate a barcode using C#:

Generate Barcode in C#

How to Generate a QR Barcode using C#

Generating a QR barcode is similar to creating other types of barcodes. Here’s how to do it:

  1. Create an instance of the BarcodeGenerator class, specifying the barcode type as EncodeTypes.QR.
  2. Generate the barcode using the BarcodeGenerator.Save(String) method.

Here’s a code sample for generating a QR barcode using C#:

Generate QR Barcode in C#

Customize the Appearance of a Barcode in C#

Customizing the appearance of a barcode is easy with the Aspose Plugin. You can modify its font, foreground color, background color, and text color. Here’s how:

  1. Create an instance of the BarcodeGenerator class.
  2. Adjust the barcode’s appearance using the BarcodeGenerator.Parameters properties, such as BarcodeGenerator.Parameters.BackColor.
  3. Generate the barcode using the BarcodeGenerator.Save(String) method.

Here’s a code sample for generating a customized Aztec barcode using C#:

Generate Aztec Barcode in C#

Add Caption in Barcodes using C#

Adding captions to barcodes can enhance their context, and the Aspose Plugin makes this process seamless. Here’s how to add a caption:

  1. Create an instance of the BarcodeGenerator class.
  2. Set the barcode’s text and type in the constructor of BarcodeGenerator.
  3. Use the CaptionAbove or CaptionBelow properties to set the caption.
  4. Save the barcode using the BarcodeGenerator.Save(String) method.

Here’s a code sample for adding a caption to a barcode using C#:

Generate Barcode with Caption in C#

Conclusion

In this article, you learned how to programmatically generate barcodes using C#. You also discovered how to customize their appearance and add captions. For more detailed information, explore the Aspose.BarCode documentation.

See Also