Products Technologies Demo Docs Blog Support Company

Using QR Codes in PDF Documents in C# .NET

QR codes are a powerful tool for embedding machine-readable information in documents. In this article, we will explore how to generate and insert them into PDF documents using C# .NET with TX Text Control. We will cover the fundamentals of QR code generation, customizing QR code content and appearance, and the best practices for integrating them into your document workflows.

Using QR Codes in PDF Documents in C# .NET

QR codes have quietly become the standard bridge between the physical and digital worlds. Users are accustomed to scanning them to instantly access information, from restaurant menus to payment systems. Integrating this functionality into generated documents, especially PDFs, opens up powerful new possibilities for modern applications.

In document workflows, QR codes are more than just a convenience feature. They can transform static documents into interactive entry points by linking invoices to online payment portals, connecting contracts to verification endpoints, and enabling instant access to supplementary resources without cluttering the document itself. In industries such as logistics, healthcare, and finance, QR codes are used to encode identifiers, track assets, and provide secure access to backend systems.

From a technical perspective, integrating QR codes directly into document generation pipelines ensures consistency, automation, and reliability. Rather than manually adding links or relying on external systems, developers can embed dynamic, data-driven QR codes when a document is created, ensuring that every generated PDF contains the necessary information.

As document processes evolve toward automation and digital-first workflows, QR codes are becoming a simple yet highly effective tool for connecting documents to systems, users, and real-time data.

With TX Text Control, developers can seamlessly integrate high-quality, dynamic QR codes and other machine-readable codes into PDFs as part of automated, professional document generation workflows.

Generating QR Codes

TX Text Control provides built-in support for generating QR codes, allowing developers to create and customize them directly within their document generation processes. To generate a QR code, you can use the TXBarcodeCore class, which supports various barcode types, including QR codes, Data Matrix, and more. You can specify which content to encode, customize the size and length of the text, and apply styling to match your document's design.

Simply add the NuGet package TXTextControl.TextControl.Core.SDK to your .NET project:

Install-Package TXTextControl.TextControl.Core.SDK

Then, generate a QR code using the following code snippet:

using var tx = new TXTextControl.ServerTextControl();

tx.Create();

string qrcodeText = "https://www.textcontrol.com";

var qrCode = new TXTextControl.Barcode.TXBarcodeCore();
qrCode.BarcodeType = TXTextControl.Barcode.BarcodeType.QRCode;
qrCode.UpperTextLength = qrcodeText.Length;
qrCode.Text = qrcodeText;

var barcodeFrame = new TXTextControl.DataVisualization.BarcodeFrame(qrCode);

tx.Barcodes.Add(barcodeFrame, - 1);

tx.Save("QRCode.pdf", TXTextControl.StreamType.AdobePDF);

First, it initializes a document processing instance using ServerTextControl, which acts as the engine for creating and manipulating the document. Then, a QR code is defined by creating a TXBarcodeCore object, setting its type to QR code, and assigning content, which, in this case, is a URL. The barcode is then wrapped in a visual container so that it can be placed inside the document and added to it. Finally, the document is saved as a PDF file, resulting in a finished document that includes the embedded QR code.

Simple QR Code in PDF

Styling the QR Code

With TX Text Control, you can customize the appearance of QR codes to match your document's design. You can adjust their size, colors, and other visual properties. This level of customization ensures that the QR code serves its functional purpose and integrates seamlessly with your document's overall aesthetic.

The following code snippet demonstrates how to customize the appearance of a QR code:

qrCode.ForeColor = Color.DarkBlue;
qrCode.BackColor = Color.LightYellow;
qrCode.Angle = 90;

In this example, the foreground color of the QR code is set to dark blue and the background color is set to light yellow. Customizing these properties allows you to create QR codes that function effectively and enhance the visual appeal of your documents.

Styled QR Code in PDF

Adding QR Codes to Headers and Footers

With TX Text Control, you can add QR codes to headers and footers, ensuring they are visible on every page of the document. This feature is particularly useful for documents like invoices, as it provides users with a consistent way to access online payment portals or additional information.

You can use the following code snippet to add a QR code to a header::

using var tx = new TXTextControl.ServerTextControl();

tx.Create();

const string qrcodeText = "https://www.textcontrol.com";

var qrCode = new TXTextControl.Barcode.TXBarcodeCore
{
    BarcodeType = TXTextControl.Barcode.BarcodeType.QRCode,
    UpperTextLength = qrcodeText.Length,
    Text = qrcodeText
};

tx.Sections[1].HeadersAndFooters.Add(TXTextControl.HeaderFooterType.Header);
tx.Sections[1]
  .HeadersAndFooters
  .GetItem(TXTextControl.HeaderFooterType.Header)
  .Barcodes
  .Add(
      new TXTextControl.DataVisualization.BarcodeFrame(qrCode),
      TXTextControl.HorizontalAlignment.Right,
      -1,
      TXTextControl.FrameInsertionMode.AboveTheText);

tx.Save("QRCode.pdf", TXTextControl.StreamType.AdobePDF);

Dynamic QR Codes in Automated Workflows

In automated document generation workflows, you can create dynamic QR codes that contain information specific to each document. For instance, you can generate a unique QR code for each invoice that links to the corresponding payment page or customer portal. This ensures that each document is personalized and functional without manual intervention.

With TX Text Control's MailMerge functionality, you can easily generate dynamic QR codes for each record in your data source. Take a look at this sample invoice template that includes a QR code. The data for the QR code is pulled from the data source, ensuring that each generated invoice has a unique QR code linking to the appropriate payment page.

Sample Invoice Template with QR Code

The following JSON data source contains information about the invoice, including the QR code content.

[
  {
    "PaymentLink": "https://portal.myinvoice.com/12345",
    "Customer_Customer": {
      "Name": "Sample Company Ltd."
    }
  },
  {
    "PaymentLink": "https://portal.myinvoice.com/67890",
    "Customer_Customer": {
      "Name": "Another Company Inc."
    }
  },
  {
    "PaymentLink": "https://portal.myinvoice.com/54321",
    "Customer_Customer": {
      "Name": "Third Company LLC"
    }
  }
]

The following code snippet demonstrates how to use this data source to generate a PDF invoice with a QR code using the MailMerge class:

using var tx = new TXTextControl.ServerTextControl();

tx.Create();
tx.Load("invoice_qrcode.tx", TXTextControl.StreamType.InternalUnicodeFormat);

var mailMerge = new TXTextControl.DocumentServer.MailMerge { TextComponent = tx };
mailMerge.MergeJsonData(System.IO.File.ReadAllText("data.json"));

tx.Save("QRCode.pdf", TXTextControl.StreamType.AdobePDF);

The screenshot below shows a generated PDF invoice with an embedded QR code. Each invoice has a unique QR code that links to its corresponding payment page. This demonstrates how dynamic QR codes can improve the functionality of generated documents in automated workflows.

Generated Invoice with QR Code

Exporting QR Codes as Images (SVG)

In addition to embedding QR codes directly into PDFs, TX Text Control allows you to export them as standalone images in formats such as SVG. This is useful if you want to use the QR code in other contexts or if you need a high-quality image for printing or web use.

To export a QR code as an SVG image, you can use the following code snippet:

using System.Drawing;

string qrcodeText = "https://www.textcontrol.com";

var qrCode = new TXTextControl.Barcode.TXBarcodeCore();
qrCode.BarcodeType = TXTextControl.Barcode.BarcodeType.QRCode;
qrCode.UpperTextLength = qrcodeText.Length;
qrCode.Text = qrcodeText;

var svgQrCode = qrCode.GetSVG(new Size(5000, 5000));

// save the svg to a file
string filePath = "qrcode.svg";
System.IO.File.WriteAllText(filePath, svgQrCode);

Typical Use Cases for QR Codes in PDFs

QR codes in PDFs are commonly used in various industries and scenarios, including:

  • Invoices and Billing: Embedding QR codes that link to online payment portals for easy and secure transactions.
  • Event Tickets: Generating QR codes that serve as digital tickets, allowing for quick scanning at entry points.
  • Product Packaging: Including QR codes in product manuals or packaging that link to instructional videos or support resources.
  • Marketing Materials: Adding QR codes to brochures or flyers that direct users to promotional websites or social media pages.
  • Healthcare Documents: Using QR codes in medical reports or prescriptions to provide access to patient portals or additional information.

In conclusion, QR codes are a powerful tool for enhancing PDF document functionality. With TX Text Control, developers can generate and customize QR codes with ease. They can integrate these codes into headers and footers, create dynamic codes in automated workflows, and export them as standalone images. These capabilities open up a wide range of possibilities for creating interactive, user-friendly documents that seamlessly connect users to digital resources.

Frequently Asked Questions

QR codes transform static PDF documents into interactive entry points by linking them to digital resources such as payment portals, verification systems, or additional content. They are widely used across industries like finance, healthcare, and logistics to connect documents with backend systems and real-time data.

You can generate QR codes using the TXBarcodeCore class provided by TX Text Control. After initializing a ServerTextControl instance, create a barcode object, set its type to QR code, assign the content to encode, and insert it into the document before exporting it as a PDF.

Yes, QR codes can be fully customized. You can adjust properties such as size, foreground and background colors, and other visual settings to ensure that the QR code matches the overall design of your document while remaining fully functional.

Yes, QR codes can be placed in headers and footers so they appear on every page of a document. This is particularly useful for invoices or reports where consistent access to links, such as payment pages or reference systems, is required.

Dynamic QR codes can be generated using data-driven approaches such as MailMerge. Each document can contain a unique QR code based on data from a source like JSON, enabling personalized documents such as invoices with individual payment links or customer-specific information.

Yes, QR codes can be exported as standalone images, including vector formats like SVG. This allows you to reuse them in other contexts such as web applications, print materials, or external systems while maintaining high quality.

Common use cases include invoices with payment links, event tickets for quick scanning, product documentation linking to support resources, marketing materials directing users to websites, and healthcare documents providing access to patient portals.

Integrating QR codes directly into the generation process ensures consistency, automation, and reliability. Developers can embed data-driven QR codes at creation time, eliminating manual steps and ensuring every document contains accurate and up-to-date information.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETASP.NET CorePDF

Adding QR Codes to PDF Documents in C# .NET

This article explains how to add QR codes to PDF documents with the Text Control .NET Server component in C#. It provides the necessary steps and code snippets for effectively implementing this…


ASP.NETASP.NET CoreE-Invoicing

Why Structured E-Invoices Still Need Tamper Protection using C# and .NET

ZUGFeRD, Factur-X, German e-invoicing rules, and how to seal PDF invoices with TX Text Control to prevent tampering. Learn how to create compliant e-invoices with C# and .NET.


ASP.NETASP.NET CoreForms

Create Fillable PDFs from HTML Forms in C# ASP.NET Core Using a WYSIWYG Template

Learn how to generate PDFs from HTML forms in ASP.NET Core using a pixel-perfect WYSIWYG template. Extract form fields from a document, render a dynamic HTML form, and merge the data server-side…


ASP.NETASP.NET CoreHTML

Why HTML to PDF Conversion is Often the Wrong Choice for Business Documents…

In this article, we explore the challenges of HTML to PDF conversion for business documents in C# .NET and present alternative solutions that offer better performance and reliability. Discover why…


ASP.NETASP.NET CoreMarkdown

A Complete Guide to Converting Markdown to PDF in .NET C#

Learn how to convert Markdown to PDF in .NET C# using Text Control's ServerTextControl component. This guide covers setup, conversion process, and customization options for generating high-quality…

Share on this blog post on: