Skip to footer content
USING IRONPDF

How to Convert QR Code to PDF

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 codes.

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.

How to Convert QR Code to PDF

  1. Install C# QR code and PDF library to create and convert QR Code to PDF.
  2. Generate a simple QR object using QrWriter.Write method from IronQR.
  3. Save the QR Code object as a Bitmap.
  4. Save the QR Code Bitmap as a File using SaveAs method.
  5. Set the QR code image path in a variable.
  6. Use File.Exists method to check if a QR code Image exists before converting.
  7. Utilize ImageToPdfConverter.ImageToPdf method from IronPDF to load the Image and convert it to a PDF object.
  8. Save the PDF using SaveAs method.

Introduction to IronQR

IronQR is an easy-to-use C# library by Iron Software 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.

Features of IronQR

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.
  • Output formats include images, streams, and PDF stamping.

To learn more about IronQR and its exciting features, please follow this documentation page.

Create a Visual Studio Project

To begin, let's create a new project in Visual Studio:

  1. Open Visual Studio and click on Create a new project.

    Qr Code To Pdf Tutorial 1 related to Create a Visual Studio Project

  2. Select Console App (.NET C#) project type.

    Qr Code To Pdf Tutorial 2 related to Create a Visual Studio Project

  3. Choose a name for your project (e.g., QRCodeToPDF) and set the location where it should be saved.

    Qr Code To Pdf Tutorial 3 related to Create a Visual Studio Project

  4. In Additional Information, select the latest version of .NET Framework. IronPDF supports the latest version of .NET.

    Qr Code To Pdf Tutorial 4 related to Create a Visual Studio Project

  5. Click Create.

Install IronQR and IronPDF Library via NuGet Package Manager

To work with IronQR and IronPDF, you need to download and install the packages using the NuGet Package Manager:

  1. In Microsoft Visual Studio, right-click on your project in the Solution Explorer.
  2. Select Manage NuGet Packages.
  3. In the Browse tab, search for IronQR.

    Qr Code To Pdf Tutorial 5 related to Install IronQR and IronPDF Library via NuGet Package Manager

  4. Select the package from the list and click Install.
  5. Accept the license terms to complete the installation.
  6. Similarly, search for IronPDF and install it.

    Qr Code To Pdf Tutorial 6 related to Install IronQR and IronPDF Library via NuGet Package Manager

Generate a QR Code using IronQR Library

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. Iron Software 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; // IronQR namespace
using IronSoftware.Drawing; // For working with general image formats

// Set your License Key for IronQR
License.LicenseKey = "YOUR-LICENSE-KEY-HERE";

// Create a QR Code object with the specified text
QrCode myQr = QrWriter.Write("hello world");

// Save QR Code as a Bitmap object
AnyBitmap qrImage = myQr.Save();

// Save QR Code Bitmap as a File with specified format
qrImage.SaveAs("qr.png");
using IronQr; // IronQR namespace
using IronSoftware.Drawing; // For working with general image formats

// Set your License Key for IronQR
License.LicenseKey = "YOUR-LICENSE-KEY-HERE";

// Create a QR Code object with the specified text
QrCode myQr = QrWriter.Write("hello world");

// Save QR Code as a Bitmap object
AnyBitmap qrImage = myQr.Save();

// Save QR Code Bitmap as a File with specified format
qrImage.SaveAs("qr.png");
Imports IronQr ' IronQR namespace
Imports IronSoftware.Drawing ' For working with general image formats

' Set your License Key for IronQR
License.LicenseKey = "YOUR-LICENSE-KEY-HERE"

' Create a QR Code object with the specified text
Dim myQr As QrCode = QrWriter.Write("hello world")

' Save QR Code as a Bitmap object
Dim qrImage As AnyBitmap = myQr.Save()

' Save QR Code Bitmap as a File with specified format
qrImage.SaveAs("qr.png")
$vbLabelText   $csharpLabel

Code Explanation

  • 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.
  • qrImage.SaveAs("qr.png"): This method saves the QR code bitmap image to a file named qr.png in the current working directory. The file format is determined by the file extension, in this case, PNG.

After running the application, we get our QR code as follows:

Qr Code To Pdf Tutorial 7 related to Code Explanation

We will load this QR Code image and use the ImageToPdfConverter class provided by IronPDF.

Introduction to IronPDF

IronPDF is a robust .NET C# library from Iron Software 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.

Qr Code To Pdf Tutorial 8 related to Introduction to IronPDF

Features of IronPDF

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, 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.
  • PDF editing capabilities: Merging, splitting, and adding watermarks are made simple with IronPDF.

To learn more about IronPDF's exciting features, please follow this documentation page.

Convert the QR Code Image to a PDF File

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; // IronPDF namespace
using System.IO; // For File operations

// Set your License Key for IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY-HERE";

// Define the file path for the QR code image
var qrImagePath = "assets/sample_qr_code.png";

// 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; // IronPDF namespace
using System.IO; // For File operations

// Set your License Key for IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY-HERE";

// Define the file path for the QR code image
var qrImagePath = "assets/sample_qr_code.png";

// 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 ' IronPDF namespace
Imports System.IO ' For File operations

' Set your License Key for IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY-HERE"

' Define the file path for the QR code image
Dim qrImagePath = "assets/sample_qr_code.png"

' Ensure that the image file exists before proceeding
If File.Exists(qrImagePath) Then
	' Convert the image to a PDF and save it
	ImageToPdfConverter.ImageToPdf( { 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.")
End If
$vbLabelText   $csharpLabel

Code Explanation

  • 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.
  • SaveAs("QRCodeImageToPDF.pdf"): Saves the generated PDF as QRCodeImageToPDF.pdf.

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.

Run the Application

Now that the code is in place, it's time to run the application and see the conversion in action. Follow these steps:

  1. Ensure that the QR code image (sample_qr_code.jpg) is correctly placed in the specified folder (e.g., the assets folder).
  2. Build and run the project in Visual Studio by pressing F5 or clicking Start.
  3. The application will convert the QR code image into a PDF if the image exists at the specified location.
  4. The generated PDF will be saved in the root of your project directory with the filename QRCodeImageToPDF.pdf.
  5. Check the PDF file to ensure the QR code image has been successfully embedded.

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:

Code Output

Conclusion

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!

Frequently Asked Questions

How can I generate a QR code and embed it into a PDF using C#?

You can generate a QR code using the IronQR library and save it as a Bitmap. Then, use IronPDF's ImageToPdfConverter class to embed the QR code image into a PDF.

What steps are involved in converting a QR code image to PDF in a .NET application?

First, generate the QR code using IronQR and save it as an image file. Next, use IronPDF's ImageToPdfConverter to convert the image file into a PDF document.

Can I use IronQR and IronPDF in a cross-platform environment?

Yes, both IronQR and IronPDF support cross-platform compatibility, allowing you to use them on Windows, Linux, macOS, Android, iOS, as well as in cloud environments like Azure and AWS.

What are the benefits of using IronPDF for QR code to PDF conversion?

IronPDF offers robust PDF manipulation capabilities, including image-to-PDF conversion, HTML support, and advanced features like merging and splitting PDFs. This makes it ideal for generating document-ready QR codes.

Is it possible to customize the appearance of a QR code using IronQR?

Yes, IronQR provides advanced customization options for styling QR codes, allowing you to adjust parameters such as color, size, and error correction levels to fit your specific needs.

How do I begin using the IronQR and IronPDF libraries in my project?

Install the IronQR and IronPDF packages using the NuGet Package Manager in Visual Studio. Search for the packages, and install them to start using their features in your .NET application.

What problem-solving capabilities does IronPDF offer for developers?

IronPDF simplifies PDF creation and manipulation with features like image-to-PDF conversion, HTML embedding, and security settings, allowing developers to efficiently handle PDF documents in their applications.

How can I ensure successful conversion of a QR code to PDF?

Verify that the QR code image is properly saved in the correct folder. Then, build and run your project in Visual Studio, ensuring the application correctly accesses and converts the image to a PDF.

Is there a way to test IronPDF's functionalities before purchasing?

Yes, IronPDF offers a free trial version, allowing you to explore its features and evaluate its capabilities before making a purchase decision.

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of ...Read More