Merge Barcodes and QR Codes

With GemBox.Document you can import your barcode data using a MergeBarcode field in a mail merge operation.

The following example shows how you can perform a simple mail merge with barcodes by importing data from an anonymous type object.

Creating Word document with barcodes with mail merge process in C# and VB.NET
Screenshot of Word file with barcodes created from mail merge
Upload your file (Drag file here)
using GemBox.Document;

class Program
    static void Main()
        // If using the Professional version, put your serial key below.

        var document = DocumentModel.Load("%InputFileName%");

        // Create data source for mail merge process.
        var data = new
            QrCode = "QR Code created with GemBox.Document",
            Code128 = "1234567890",
            Ean13 = "5901234123457"

        // Execute mail merge process.

        document.Save("Barcodes Merge Output.%OutputFileType%");
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.

        Dim document = DocumentModel.Load("%InputFileName%")

        ' Create data source for mail merge process.
        Dim data = New With
            .QrCode = "QR Code created with GemBox.Document",
            .Code128 = "1234567890",
            .Ean13 = "5901234123457"

        ' Execute mail merge process.

        document.Save("Mail Merge Output.%OutputFileType%")

    End Sub
End Module

Similarly to Microsoft Word, GemBox.Document creates a DisplayBarcode field when the MergeBarcode field is merged. During this process all barcode types and field switches described in the official documentation are supported.

However, when saving the document to PDF, XPS, or image file formats, only the following barcode types are supported:

  • QR Code
  • Code 39 (also called Code 3 of 9)
  • Code 128
  • EAN 13 / JAN 13
  • EAN 8 / JAN 8
  • UPCA
  • ITF14
  • NW7 (Codabar)

The following switches can be used to customize the barcode when saving to PDF, XPS, or image file formats:

  • \h - the height of the barcode in twips.
  • \s - the scaling factor of the QR Code.
  • \q - the error correction level of the QR Code.
  • \f - the foreground color of the barcode.
  • \b - the background color of the barcode.
  • \t - displays the barcode text along with the image.
  • \d - add start/stop characters (valid for Code39 and NW7)

You can find more information about the DisplayBarcode field in our Barcodes and QR codes example.

See also

Next steps

GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API. How about testing it today?

Download Buy