Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Quick Response codes, known as QR codes, are two-dimensional barcodes capable of storing various information, including URLs, contact details, or plain text. They are widely used in marketing, payment systems, inventory management, printing, and more. As their popularity grows, developers increasingly need to handle QR codes within applications, such as reading and embedding them into documents like PDFs as well as ways to generate QR code and QR code generation.
In this article, I’ll show you how easy it is to create and convert a QR Code image to PDF using the IronQR and IronPDF libraries.
Install C# QR code and PDF library to create and convert QR Code to PDF
Generate a simple QR object using QrWriter.Write method from IronQR
Save the QR Code object as a Bitmap
Save the QR Code Bitmap as a File using `SaveAs` method
Set the QR code image path in a variable
Use File.Exists method to check if a QR code Image exists before converting
Utilize ImageToPdfConverter.ImageToPdf method from IronPDF to load the Image and convert it to a PDF object
IronQR is an easy-to-use C# library by IronSoftware that allows developers to generate static QR codes, style, and read QR codes in .NET applications. Its simplicity and robust features make it an ideal tool for integrating QR code functionality into desktop, web, and mobile apps. One of its key strengths is the ability to handle QR codes across a wide range of platforms, including Windows, Linux, macOS, Android, iOS, and cloud environments like Azure and AWS.
The IronQR library provides a robust solution for generating QR codes, allowing developers to create static and dynamic QR codes for various applications easily. With its advanced features, IronQR facilitates reading QR codes and integrates seamlessly with PDF documents, enabling users to generate, print, and embed QR codes directly into their PDFs.
IronQR offers a range of features that prioritize accuracy, speed, and ease of use:
Cross-platform compatibility with .NET (Core, Standard, Framework), supporting various environments, including web, desktop, and mobile apps.
Machine learning-powered QR code detection for reading even complex QR codes.
Supports various image formats (jpg, png, gif, bmp, etc.).
Advanced customization options for styling QR codes, such as resizing, adding logos, and adjusting error correction levels.
To learn more about IronQR and its exciting features, please follow this documentation page.
To begin, let's create a new project in Visual Studio:
Open Visual Studio and click on Create a new project.
Select Console App (.NET C#) project type.
Choose a name for your project (e.g., QRCodeToPDF) and set the location where it should be saved.
In Additional Information, select the latest version of .NET Framework. IronPDF supports the latest version of .NET.
To work with IronQR and IronPDF, you need to download and install the packages using the NuGet Package Manager:
In Microsoft Visual Studio, right-click on your project in the Solution Explorer.
Select Manage NuGet Packages.
In the Browse tab, search for IronQR.
Select the package from the list and click Install.
Accept the license terms to complete the installation.
Similarly, search for IronPDF and install it.
To convert a QR code image into a PDF, we'll first need a QR code image. You can use any QR code generator library or online tool to create a QR code. IronSoftware provides a dedicated QR code library named "IronQR" to create QR codes, and I'm going to use it here to generate a simple QR code.
The following code example will allow us to create a QR code with the text Hello World:
using IronQr;
using IronSoftware.Drawing;
License.LicenseKey = “YOUR-LICENSE-KEY-HERE”;
// Create a QR Code object
QrCode myQr = QrWriter.Write("hello world");
// Save QR Code as a Bitmap
AnyBitmap qrImage = myQr.Save();
// Save QR Code Bitmap as File
qrImage.SaveAs("qr.png");
using IronQr;
using IronSoftware.Drawing;
License.LicenseKey = “YOUR-LICENSE-KEY-HERE”;
// Create a QR Code object
QrCode myQr = QrWriter.Write("hello world");
// Save QR Code as a Bitmap
AnyBitmap qrImage = myQr.Save();
// Save QR Code Bitmap as File
qrImage.SaveAs("qr.png");
Imports IronQr
Imports IronSoftware.Drawing
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'License.LicenseKey = "YOUR-LICENSE-KEY-HERE”; QrCode myQr = QrWriter.Write("hello world"); AnyBitmap qrImage = myQr.Save(); qrImage.SaveAs("qr.png");
QrWriter.Write("hello world"): This method generates a QR code that encodes the string "hello world." The result is an instance of the QrCode class, representing the generated QR code.
myQr.Save(): This method converts the QR code object into a bitmap image format. The Save() method returns an instance of AnyBitmap, a flexible image representation supporting various formats.
AnyBitmap qrImage: This variable holds the bitmap image of the generated QR code.
After running the application, we get our QR code as follows:
We will load this QR Code image and use the ImageToPdfConverter class provided by IronPDF.
IronPDF is a robust .NET C# library from IronSoftware that easily creates, manipulates, and converts PDF documents in .NET applications. With IronPDF, developers can easily embed images (including QR codes) into a PDF document template, making it perfect for tasks like converting QR code images into a document-ready PDF.
IronPDF provides HTML to PDF conversion, which allows developers to directly embed QR code images in an HTML template and then generate PDF documents seamlessly. The embedded QR code formatting is preserved in the document, allowing error-free scanning of the QR codes.
IronPDF offers a wide range of PDF manipulation tools, including:
Cross-platform compatibility: Supports .NET Core, .NET Framework, and .NET Standard, running on Windows, Linux, macOS, docker, Azure, and AWS.
Image-to-PDF conversion: Effortlessly converts image files, such as JPEGs or PNGs, Bitmap into PDFs.
HTML and CSS support: For creating customizable PDFs from web pages.
Security features: Includes password protection and encryption for securing sensitive PDF documents.
To learn more about IronPDF's exciting features, please follow this documentation page.
Now, with everything set up perfectly, the following code example will help you convert a QR code image to a PDF using IronPDF:
using IronPdf;
using System.IO;
using System.Linq;
License.LicenseKey = “YOUR-LICENSE-KEY-HERE”;
var qrImagePath = "assets/sample_qr_code.png";
// To ensure that the image file exists before proceeding
if (File.Exists(qrImagePath))
{
// Convert the image to a PDF and save it
ImageToPdfConverter.ImageToPdf(new[] { qrImagePath }).SaveAs("QRCodeImageToPDF.pdf");
Console.WriteLine("QR Code image has been successfully converted to a PDF.");
}
else
{
Console.WriteLine("QR Code image not found. Please check the file path.");
}
using IronPdf;
using System.IO;
using System.Linq;
License.LicenseKey = “YOUR-LICENSE-KEY-HERE”;
var qrImagePath = "assets/sample_qr_code.png";
// To ensure that the image file exists before proceeding
if (File.Exists(qrImagePath))
{
// Convert the image to a PDF and save it
ImageToPdfConverter.ImageToPdf(new[] { qrImagePath }).SaveAs("QRCodeImageToPDF.pdf");
Console.WriteLine("QR Code image has been successfully converted to a PDF.");
}
else
{
Console.WriteLine("QR Code image not found. Please check the file path.");
}
Imports IronPdf
Imports System.IO
Imports System.Linq
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'License.LicenseKey = "YOUR-LICENSE-KEY-HERE”; var qrImagePath = "assets/sample_qr_code.png"; if (File.Exists(qrImagePath)) { ImageToPdfConverter.ImageToPdf(new[] { qrImagePath }).SaveAs("QRCodeImageToPDF.pdf"); Console.WriteLine("QR Code image has been successfully converted @to a PDF."); } else { Console.WriteLine("QR Code image @not found.Please check the file path."); }
File.Exists(qrImagePath): Verifies if the QR code image exists at the specified path before proceeding.
ImageToPdfConverter.ImageToPdf(new[] { qrImagePath }): Converts the QR code image to a PDF using IronPDF’s image-to-PDF conversion method.
To convert multiple QR code images into a single PDF, please visit this Images to PDF page. For more code samples, please visit this code example page here.
Now that the code is in place, it's time to run the application and see the conversion in action. Follow these steps:
Ensure that the QR code image (sample_qr_code.jpg) is correctly placed in the specified folder (e.g., the assets folder).
Build and run the project in Visual Studio by pressing F5 or clicking Start.
The application will convert the QR code image into a PDF if the image exists at the specified location.
The generated PDF will be saved in the root of your project directory with the filename QRCodeImageToPDF.pdf.
You should now have a PDF containing your QR code image, which can be shared, printed, or archived. Here is the output PDF with the QR code image we used:
Using IronQR and IronPDF, creating and converting a QR code image to a PDF is simple and efficient. By following the steps outlined above, you can easily create a QR code image, convert it, and save it as a PDF in just a few lines of code. Whether for business or personal use, this approach ensures that your QR code is document-ready in PDF format and can be shared over the internet without any data or pixel loss.
IronPDF provides a free trial so you can explore its features and capabilities for yourself. For those ready to unlock the full potential of the library, licenses start at $749, offering comprehensive access to all functionalities. Don't miss the opportunity to enhance your PDF generation—try IronPDF today by downloading it!
9 .NET API products for your office documents