Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, you'll learn how to generate barcodes and QR codes in C# using Iron Barcode within a .NET framework. The process begins with installing the Iron Barcode library via the NuGet package manager. You can use either the console or the graphical user interface to do so. Once installed, including the Iron Barcode namespace is essential. The guide walks you through writing a single line of code to create a barcode, illustrating how to encode data such as a product ID or website link. The tutorial explains saving the generated barcode in various formats, including PNG and HTML. It also covers how to generate a QR code by altering the encoding scheme and demonstrates adding annotations like text above or below the barcode or QR code. The tutorial concludes by showing how to access the saved barcode file in your project directory, providing a straightforward solution for integrating barcode and QR code generation into your C# applications.
Here is the corrected and formatted code snippet to generate a barcode and QR code using Iron Barcode:
// Install IronBarcode from NuGet package manager before using this code.
// Use the following command in the Package Manager Console: Install-Package IronBarCode
using IronBarCode; // Import the IronBarcode namespace
class BarcodeExample
{
static void Main(string[] args)
{
// Creating a Barcode
// "123456" is the data to be encoded in the barcode.
BarcodeWriter.CreateBarcode("123456", BarcodeEncoding.Code128)
.SaveAsPng("barcode.png");
// Creating a QR Code
// "https://example.com" is the data to be encoded in the QR code.
var qrCode = BarcodeWriter.CreateQRCode("https://example.com");
qrCode.SaveAsPng("qrcode.png");
// Adding annotations to the QR Code
qrCode.AddAnnotationTextAboveBarcode("Visit our Website")
.AddAnnotationTextBelowBarcode("Scan the QR code for more info.")
.SaveAsPng("annotated_qrcode.png");
// Information
// The data will be saved in the default project directory unless a different path is specified.
System.Console.WriteLine("Barcodes have been generated and saved successfully.");
}
}
// Install IronBarcode from NuGet package manager before using this code.
// Use the following command in the Package Manager Console: Install-Package IronBarCode
using IronBarCode; // Import the IronBarcode namespace
class BarcodeExample
{
static void Main(string[] args)
{
// Creating a Barcode
// "123456" is the data to be encoded in the barcode.
BarcodeWriter.CreateBarcode("123456", BarcodeEncoding.Code128)
.SaveAsPng("barcode.png");
// Creating a QR Code
// "https://example.com" is the data to be encoded in the QR code.
var qrCode = BarcodeWriter.CreateQRCode("https://example.com");
qrCode.SaveAsPng("qrcode.png");
// Adding annotations to the QR Code
qrCode.AddAnnotationTextAboveBarcode("Visit our Website")
.AddAnnotationTextBelowBarcode("Scan the QR code for more info.")
.SaveAsPng("annotated_qrcode.png");
// Information
// The data will be saved in the default project directory unless a different path is specified.
System.Console.WriteLine("Barcodes have been generated and saved successfully.");
}
}
' Install IronBarcode from NuGet package manager before using this code.
' Use the following command in the Package Manager Console: Install-Package IronBarCode
Imports IronBarCode ' Import the IronBarcode namespace
Friend Class BarcodeExample
Shared Sub Main(ByVal args() As String)
' Creating a Barcode
' "123456" is the data to be encoded in the barcode.
BarcodeWriter.CreateBarcode("123456", BarcodeEncoding.Code128).SaveAsPng("barcode.png")
' Creating a QR Code
' "https://example.com" is the data to be encoded in the QR code.
Dim qrCode = BarcodeWriter.CreateQRCode("https://example.com")
qrCode.SaveAsPng("qrcode.png")
' Adding annotations to the QR Code
qrCode.AddAnnotationTextAboveBarcode("Visit our Website").AddAnnotationTextBelowBarcode("Scan the QR code for more info.").SaveAsPng("annotated_qrcode.png")
' Information
' The data will be saved in the default project directory unless a different path is specified.
System.Console.WriteLine("Barcodes have been generated and saved successfully.")
End Sub
End Class
Further Reading: C# QR Code Generator for .NET