# Enhancing Documents with QR Codes and Barcodes in .NET C#: A Comprehensive Guide

> QR codes and barcodes can be highly beneficial on various documents or PDFs, providing a convenient way to access information, verify authenticity, track items, and enhance user interaction. This article shows how to create documents with QR codes and barcodes in .NET C# using TX Text Control .NET Server.

- **Author:** Bjoern Meyer
- **Published:** 2024-07-11
- **Modified:** 2026-07-17
- **Description:** QR codes and barcodes can be highly beneficial on various documents or PDFs, providing a convenient way to access information, verify authenticity, track items, and enhance user interaction. This article shows how to create documents with QR codes and barcodes in .NET C# using TX Text Control .NET Server.
- **6 min read** (1168 words)
- **Tags:**
  - ASP.NET
  - ASP.NET Core
  - Document Automation
  - MailMerge
  - Barcode
  - QR Code
- **Web URL:** https://www.textcontrol.com/blog/2024/07/11/enhancing-documents-with-qr-codes-and-barcodes-in-net-csharp-a-comprehensive-guide/
- **LLMs URL:** https://www.textcontrol.com/blog/2024/07/11/enhancing-documents-with-qr-codes-and-barcodes-in-net-csharp-a-comprehensive-guide/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2024/07/11/enhancing-documents-with-qr-codes-and-barcodes-in-net-csharp-a-comprehensive-guide/llms-full.txt
- **GitHub Repository:** https://github.com/TextControl/TXTextControl.Server.Barcodes

---

QR codes and barcodes are great for adding value to documents and PDF files by providing easy access to information, authenticating information, tracking items and improving interactivity. A barcode can bridge the gap between paper or digital human-readable documents and digital information in web portals or web applications. Most users are familiar with QR codes and barcodes, which are ubiquitous in many processes such as:

- Product packaging
- Invoices
- Inventory management
- Event ticketing
- Boarding passes
- Payment systems

There are industries in which processes are no longer possible without the use of barcodes. This includes healthcare, where patient data can be accessed directly by scanning a wristband worn by a patient, or daily medication doses can be tracked. Or logistics, where orders can be tracked or found in the warehouse by simply scanning an item code on a packing slip or other piece of documentation. In the retail industry, barcodes are used to track inventory, manage stock levels, and speed up the checkout process.

### What is a barcode?

A barcode is a machine-readable representation of data in a visual format. It consists of lines of varying widths and spacing that are read by a barcode scanner. A QR code is a type of barcode that can store more information than a traditional barcode. It is a two-dimensional code that can store text, URLs, contact information, and other data.

Most typical barcodes are:

- **QR code**
    
    ![QR Code](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/qr.webp "QR Code")
    
    A QR code is a two-dimensional barcode that can store more information than a traditional barcode. It is commonly used in marketing, advertising, and other applications where more information needs to be stored in a small space.
- **UPC (Universal Product Code)**
    
    ![UPC Code](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/upc.webp "UPC Code")
    
    A UPC code is a type of barcode that is commonly used in retail stores to track inventory and sales. It consists of 12 digits that are read by a barcode scanner.
- **EAN (European Article Number)**
    
    ![EAN Code](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/ean.webp "EAN Code")
    
    An EAN code is a type of barcode that is commonly used in Europe to track inventory and sales. It consists of 13 digits that are read by a barcode scanner.
- **Code 39**
    
    ![Code 39](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/code39.webp "Code 39")
    
    Code 39 is a type of barcode that is commonly used in logistics and inventory management. It consists of lines of varying widths and spacing that are read by a barcode scanner.

### Example: Packing Slip

Suppose you have a packing slip containing a list of items to be shipped to a customer. To track an item in the warehouse or during shipping, each item has a barcode that can be scanned. The barcode can be scanned using a barcode scanner or a mobile device with a barcode scanning application. The barcode contains information about the item, such as the item number, description, and quantity.

Look at the following screenshot of a packing slip containing barcodes in various places, generated using TX Text Control. TX Text Control provides out-of-the-box support for all industry-standard 1D and 2D barcodes.

![Packing Slip created with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/slip.webp "Packing Slip created with TX Text Control")

#### Generating the Packing Slip

Creating this packing slip is very easy using TX Text Control's MailMerge engine. First, as shown below, we need a data source, such as a JSON object.

```
[
    {
        "packing_slip_guid": "12345678-1234-1234-1234-123456789012",
        "dispatch_date": "2024-01-01",
        "recipient": {
            "id": 1,
            "name": "John Doe",
            "company": "Company A",
            "address": {
                "street": "123 Main St",
                "city": "Anytown",
                "state": "CA",
                "zip": "12345"
            }
        },
        "product": {
            "product_id": 1,
            "name": "Product 1",
            "qty": "Product 1 Description",
            "code": "123456789012"
        },
        "items": [
            {
                "item_id": 1,
                "name": "Item 1",
                "description": "Description 1",
                "quantity": 1,
                "price": 100,
                "upc": "12345678901"
            },
            {
                "item_id": 2,
                "name": "Item 2",
                "description": "Description 2",
                "quantity": 2,
                "price": 200,
                "upc": "12345678902"
            },
            {
                "item_id": 3,
                "name": "Item 3",
                "description": "Description 3",
                "quantity": 3,
                "price": 300,
                "upc": "12345678903"
            },
            [...]
        ]
    }
]
```

Next, we need a template document that contains merge fields and barcodes. The merge fields are replaced with data from the data source, and the barcodes are generated using the same data. In the following screenshot you can see the created template in the WYSIWYG document editor of TX Text Control, which can be easily integrated into your application.

![Packing Slip created with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/template.webp "Packing Slip created with TX Text Control")

The out-of-the-box user interface provides all the functionality needed to insert merge fields, repeating sections, and barcodes.

![Packing Slip created with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/template2.webp "Packing Slip created with TX Text Control")

Barcodes can be mapped to a data source field to update with the correct values during final document generation.

![Packing Slip created with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/merge.gif "Packing Slip created with TX Text Control")

### Preparing the Application

A .NET 8 console application is created for the purposes of this demo.

> #### Prerequisites
> 
>  The following tutorial requires a trial version of TX Text Control .NET Server.
> 
> - [Download Trial Version](https://www.textcontrol.com/product/tx-text-control-dotnet-server/download/)

1. In Visual Studio, create a new *Console App* using .NET 8.
2. In the *Solution Explorer*, select your created project and choose *Manage NuGet Packages...* from the *Project* main menu.
    
    Select *Text Control Offline Packages* from the *Package source* drop-down.
    
    Install the latest versions of the following package:
    
    
    - TXTextControl.TextControl.ASP.SDK
    
    ![Create PDF](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/11/a/assets/step1.webp "Create PDF")
3. Download the sample template and JSON data from the GitHub repository at the end of this article and add it to your project.
4. Open the project settings by double-clicking the project node in the *Solution Explorer* and add the *UseWindowsForms* property to the *PropertyGroup* section. Your completed *.csproj* file should look like this:
    
    ```
    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0-windows</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <UseWindowsForms>true</UseWindowsForms>
        <Nullable>enable</Nullable>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="TXTextControl.TextControl.ASP.SDK" Version="32.0.3" />
      </ItemGroup>
    
      <ItemGroup>
        <None Update="data.json">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </None>
        <None Update="packing_slip.tx">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </None>
      </ItemGroup>
    
    </Project>
    ```

### Creating the Document

1. Open the *Program.cs* file and add the following code:
    
    ```
    using TXTextControl.DocumentServer;
    
    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
    {
    	tx.Create();
    	tx.Load("packing_slip.tx", TXTextControl.StreamType.InternalUnicodeFormat);
    
    	MailMerge mailMerge = new MailMerge()
    	{
    		TextComponent = tx
    	};
    
    	string jsonData = System.IO.File.ReadAllText("data.json");
    
    	mailMerge.MergeJsonData(jsonData);
    
    	tx.Save("output.pdf", TXTextControl.StreamType.AdobePDF);
    }
    ```

When running the application, the document is created and saved as *output.pdf* in the project directory. The barcodes are generated using the data from the JSON data source.

### Conclusion

Barcodes are a great way to add value to documents and PDF files by providing easy access to information, authenticating information, tracking items, and improving interactivity. TX Text Control provides out-of-the-box support for all industry-standard 1D and 2D barcodes. The MailMerge class can be used to merge data into a template document and generate a final document with barcodes.

Download the sample project from GitHub and test it with your own data.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Document Automation 101: Leveraging TX Text Control for Business Efficiency in .NET C# Applications](https://www.textcontrol.com/blog/2024/07/09/document-automation-101-leveraging-tx-text-control-for-business-efficiency-in-net-c-applications/llms.txt)
- [Using QR Codes to Open Documents in Document Portals](https://www.textcontrol.com/blog/2022/07/14/using-qr-codes-to-open-documents-in-document-portals/llms.txt)
- [AI Natural Language Document Generation with MCP and TX Text Control .NET](https://www.textcontrol.com/blog/2026/07/16/ai-natural-language-document-generation-with-mcp-server-and-tx-text-control-dotnet/llms.txt)
- [Create SignFabric Envelopes from Mail Merge Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/23/create-signfabric-envelopes-from-mail-merge-templates-using-dotnet-csharp/llms.txt)
- [Using QR Codes in PDF Documents in C# .NET](https://www.textcontrol.com/blog/2026/04/21/using-qr-codes-in-pdf-documents-in-csharp-dotnet/llms.txt)
- [5 Document Workflows You Can Automate With JavaScript Rich Text Editor](https://www.textcontrol.com/blog/2026/01/14/five-document-workflows-you-can-automate-with-javascript-rich-text-editor/llms.txt)
- [Why Document Processing Libraries Require a Document Editor](https://www.textcontrol.com/blog/2025/12/04/why-document-processing-libraries-require-a-document-editor/llms.txt)
- [Adding QR Codes to PDF Documents in C# .NET](https://www.textcontrol.com/blog/2025/07/15/adding-qr-codes-to-pdf-documents-in-csharp-dotnet/llms.txt)
- [Use MailMerge in .NET on Linux to Generate Pixel-Perfect PDFs from DOCX Templates](https://www.textcontrol.com/blog/2025/05/27/use-mailmerge-in-dotnet-on-linux-to-generate-pixel-perfect-pdfs-from-docx-templates/llms.txt)
- [Generating Dynamic NDAs Using TX Text Control MailMerge in C# .NET](https://www.textcontrol.com/blog/2025/04/08/generating-dynamic-ndas-using-tx-text-control-mailmerge-in-csharp-dotnet/llms.txt)
- [Designing a Maintainable PDF Generation Web API in ASP.NET Core (Linux) C# with Clean Architecture and TX Text Control](https://www.textcontrol.com/blog/2025/03/27/designing-a-maintainable-pdf-generation-web-api-in-asp-net-core-linux-c-sharp-with-clean-architecture-and-tx-text-control/llms.txt)
- [Manipulating Table Cells During the MailMerge Process in .NET C#](https://www.textcontrol.com/blog/2024/12/03/manipulating-table-cells-during-the-mailmerge-process-in-net-csharp/llms.txt)
- [When to Generate Documents Server-Side Instead of Client-Side: A Focus on Data Security](https://www.textcontrol.com/blog/2024/10/04/when-to-generate-documents-server-side-instead-of-client-side-a-focus-on-data-security/llms.txt)
- [Mail Merge: Inserting Merge Blocks using the DataSourceManager in C#](https://www.textcontrol.com/blog/2024/10/02/mail-merge-inserting-merge-blocks-using-the-datasourcemanager-in-csharp/llms.txt)
- [Creating Advanced Tables in PDF and DOCX Documents with C#](https://www.textcontrol.com/blog/2024/09/30/creating-advanced-tables-in-pdf-and-docx-documents-with-csharp/llms.txt)
- [Designing the Perfect Contract Template for MailMerge in C#](https://www.textcontrol.com/blog/2024/09/26/designing-the-perfect-contract-template-for-mailmerge-in-csharp/llms.txt)
- [Video Tutorial: Creating a MailMerge Template and JSON Data Structure](https://www.textcontrol.com/blog/2024/08/16/video-tutorial-creating-a-mailmerge-template-and-json-data-structure/llms.txt)
- [Getting Started Video Tutorial: How to use the MailMerge and ServerTextControl Classes in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-use-the-mailmerge-and-servertextcontrol-classes-in-asp-net-core-c/llms.txt)
- [Getting Started Videos: New Text Control YouTube Channel](https://www.textcontrol.com/blog/2024/08/02/getting-started-videos-new-text-control-youtube-channel/llms.txt)
- [Best Practices for Mail Merge and Form Field Processing in ASP.NET Core C# Applications](https://www.textcontrol.com/blog/2024/07/30/best-practices-for-mail-merge-and-form-field-processing-in-asp-net-core-csharp-applications/llms.txt)
- [Advantages of Flow Type Layout Reporting vs. Banded Reporting or PDF Template Engines in .NET C#](https://www.textcontrol.com/blog/2024/07/29/advantages-of-flow-type-layout-reporting-vs-banded-reporting-or-pdf-template-engines-in-net-c-sharp/llms.txt)
- [Designing a MailMerge Web API Endpoint with ASP.NET Core in C#](https://www.textcontrol.com/blog/2024/07/12/designing-a-mailmerge-web-api-endpoint-with-asp-net-core-in-c-sharp/llms.txt)
- [Merging Templates with MailMerge with Different Merge Field Settings in C#](https://www.textcontrol.com/blog/2023/12/16/merging-templates-with-mailmerge-with-different-merge-field-settings/llms.txt)
- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [MailMerge: Working with Image Placeholders](https://www.textcontrol.com/blog/2022/12/22/mailmerge-working-with-image-placeholders/llms.txt)
