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

    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

    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

    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

    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

Generating the Packing Slip

Creating this packing slip is very easy using TX Text Control's MailMerge TX Text Control .NET Server for ASP.NET
DocumentServer Namespace
MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services.
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"
},
[...]
]
}
]
view raw test.json hosted with ❤ by GitHub

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

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

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

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 for ASP.NET.

  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

  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>
    view raw test.csproj hosted with ❤ by GitHub

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);
    }
    view raw test.cs hosted with ❤ by GitHub

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.