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, we explore how to use the Iron Barcode library to generate and manage QR codes. After setting up the library, we start by importing the Iron Barcode namespace, which provides necessary methods for barcode operations. The tutorial demonstrates creating a QR code that encodes a URL using the CreateBarcode
method. This method allows specifying the encoding type, such as QR code, and generates the corresponding code. Once generated, the QR code can be saved as an HTML file, making it accessible through any web browser. Additionally, we explore generating a data URL, which is a Base64 encoded string representing the QR code, useful for embedding directly into web pages without needing external files. Another approach involves using the ToHtmlTag
method to get an HTML representation of the QR code. Running the project, we observe the console output showcasing the data URL and HTML tag representation. These methods offer a compact and efficient way to integrate QR codes into web applications, with easy sharing and display options. The tutorial concludes by encouraging viewers to subscribe for more tips from Iron Software and to explore their trial subscription for firsthand experience with the software.
Here is an illustrative C# example using the Iron Barcode library:
using System;
using IronBarCode;
class Program
{
static void Main(string[] args)
{
// Creating a QR code that encodes a URL
var url = "https://example.com";
// Generate the QR code
GeneratedBarcode qrCode = BarcodeWriter.CreateBarcode(url, BarcodeWriterEncoding.QRCode);
// Saving the QR code as an HTML file
qrCode.SaveAsHtmlFile("QRCode.html");
Console.WriteLine("QR Code saved as HTML file: QRCode.html");
// Generating and displaying the data URL (Base64 representation)
string dataUrl = qrCode.ToDataUrl();
Console.WriteLine("QR Code Data URL: " + dataUrl);
// Generating and displaying the HTML tag representation
string htmlTag = qrCode.ToHtmlTag();
Console.WriteLine("QR Code HTML Tag: " + htmlTag);
}
}
using System;
using IronBarCode;
class Program
{
static void Main(string[] args)
{
// Creating a QR code that encodes a URL
var url = "https://example.com";
// Generate the QR code
GeneratedBarcode qrCode = BarcodeWriter.CreateBarcode(url, BarcodeWriterEncoding.QRCode);
// Saving the QR code as an HTML file
qrCode.SaveAsHtmlFile("QRCode.html");
Console.WriteLine("QR Code saved as HTML file: QRCode.html");
// Generating and displaying the data URL (Base64 representation)
string dataUrl = qrCode.ToDataUrl();
Console.WriteLine("QR Code Data URL: " + dataUrl);
// Generating and displaying the HTML tag representation
string htmlTag = qrCode.ToHtmlTag();
Console.WriteLine("QR Code HTML Tag: " + htmlTag);
}
}
Imports System
Imports IronBarCode
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Creating a QR code that encodes a URL
Dim url = "https://example.com"
' Generate the QR code
Dim qrCode As GeneratedBarcode = BarcodeWriter.CreateBarcode(url, BarcodeWriterEncoding.QRCode)
' Saving the QR code as an HTML file
qrCode.SaveAsHtmlFile("QRCode.html")
Console.WriteLine("QR Code saved as HTML file: QRCode.html")
' Generating and displaying the data URL (Base64 representation)
Dim dataUrl As String = qrCode.ToDataUrl()
Console.WriteLine("QR Code Data URL: " & dataUrl)
' Generating and displaying the HTML tag representation
Dim htmlTag As String = qrCode.ToHtmlTag()
Console.WriteLine("QR Code HTML Tag: " & htmlTag)
End Sub
End Class
Import the Iron Barcode Namespace: Ensure you have imported the IronBarCode
namespace to access the necessary classes and methods.
Create and Configure Barcode: Use the BarcodeWriter.CreateBarcode
method to generate a QR code with a specified encoding type.
Save as HTML: Save the generated QR code to an HTML file with SaveAsHtmlFile
for easy web browser access.
Data URL and HTML Tag: Use ToDataUrl
and ToHtmlTag
for convenient representations, which can be embedded directly into web applications.
Further Reading: How to Export Barcodes as HTML