C# Data Matrix Barcode Generator Library
How to create, print Data Matrix 2d barcodes in PDF, Tiff, images using C#.NET Control


Generate Data Matrix Barcode Image Using C#.NET code in ASP.NET Core, MVC, .NET Framework, WinForms, WPF Windows application.









C# Data Matrix Generator Plug-in Overview



RasterEdge DocImage SDK Barcode Creator Add-on for .NET has two main functions. One function is to help C#.NET developers generate Data Matrix barcode on common image files including png, jpeg/jpg, gif, and bmp. And the other is to insert Data Matrix barcode into C#.NET document processing application. Users can freely embed Data Matrix into various documents including TIFF, PDF, Word, Excel and PowerPoint.



  • Draw scannable Data Matrix barcodes using Visual C#.NET programming
  • Write, create Data Matrix 2D barcode images on Png, Jpeg, Gif, and Bmp file formats
  • Add and print Data Matrix to TIFF, PDF, Word, Excel as well as PowerPoint in Visual C#.NET
  • Customize various Data Matrix settings, like image size, rotation/orientation, data mode, margins, ECL, color and more
  • Easily generate Data Matrix barcode images in C#.NET Windows & ASP.NET web applications
  • Compatible with latest GS1 specification for valid barcode scanning


Besides, RasterEdge.com also provides other Data Matrix barcoding solutions & tutorials, like how to generate Data Matrix in VB.NET and how to read/scan Data Matrix in C# , for developers to get to know more about our Data Matrix C# & VB.NET generator and decoder.







Data Matrix data encoding in C#


Encoding character set and Data Matrix barcode data mode

Data Matrix barcode supports encoding both full ASCII chars and extended ASCII chars



Data Matrix data mode

To encode the above character sets, QR Code defines five encoding data modes.

  • Auto: C# barcode library will automatically use the right Data Matrix data modes to encode data message.
  • ASCII: Encode double digit numerics; ASCII values 0 - 127 and Extended ASCII values 128 - 255
  • C40: Encode Upper-case alphanumeric; Lower case and special characters
  • Text: Encode Lower-case alphanumeric; Upper case and special characters
  • X12: Encode ANSI X12 EDI data set
  • EDIFACT: Encode ASCII values 32 - 94
  • Base 256: Encode All byte values 0 - 255



Data Matrix maximum data length

Depends on Data Matrix data mode used, Data Matrix maximum character length are

  • alphanumeric data: 2,335 characters
  • byte data: 1,555 characters
  • numeric data: 3,116 digits







Data Matrix Barcode Special Characters Encoding using C#




How to generate GS1 compatible Data Matrix barcodes using C#

GS1 Data Matrix barcode is using Data Matrix barcode to encode GS1 format data message.

To create valid GS1 Data Matrix using C# Data Matrix barcode generator library, you need apply the following options in class RasterEdge.XImage.BarcodeCreator.DataMatrix using C# code in your ASP.NET Core, MVC, Windows aspplications.

  • FNC1: The value should be RasterEdge.XImage.BarcodeCreator.FNC1.FNC1_1ST_POS.
  • DataMode: The value should be DataMatrixDataMode.Auto
  • Data: Valid GS1 data message includes pairs of AI code and AI data. Using data matrix generator C# library, all AI codes should be surrounded by parentheses. For example: (11)010101(15)020202



            DataMatrix barcode = new DataMatrix();

            barcode.Data = "(10)ABC123(17)050101";

            barcode.DataMode = DataMatrixDataMode.Auto;

            barcode.FNC1 = FNC1.FNC1_1ST_POS;


            barcode.AutoResize = true;
            barcode.UOM = UnitOfMeasure.INCH;
            barcode.BarcodeWidth = 2F;
            barcode.BarcodeHeight = 2F;
            barcode.Resolution = 300;

            Bitmap datamatrixBitmap = barcode.ToImage();
            datamatrixBitmap.Save(
                @"W:\Projects\Test-Output\RasterEdge.com\NetCoreSDK\barcode-data-matrix-gs1-data.png");


How to generate Data Matrix barcode with international characters encoded using C#

It is really easy to generate Data Matrix with non-English characters encoded.

  1. Convert characters to byte array using UTF8 encoding.
  2. Generate Data Matrix with converted byte array using DataMatrixDataMode.Base256 data mode.



Following properties should be applied to encode international characters in Data Matrix using C#:

  • ProcessTilde: Set to enable '~' in data message.
  • DataMode:It should be DataMatrixDataMode.Base256
  • Data: The international characters should be converted to byte array using UTF8 encoding.



            DataMatrix barcode = new DataMatrix();

            string message = "สวัสดี";
            byte[] bytes = Encoding.UTF8.GetBytes(message);
            StringBuilder messageInBytes = new StringBuilder();
            foreach (byte b in bytes)
                messageInBytes.Append("~" + b.ToString().PadLeft(3, '0'));

            barcode.Data = messageInBytes.ToString();
            barcode.ProcessTilde = true;
            barcode.DataMode = DataMatrixDataMode.Base256;

            //  Set barcode size to 2 inch x 2 inch
            barcode.AutoResize = true;
            barcode.UOM = UnitOfMeasure.INCH;
            barcode.BarcodeWidth = 2F;
            barcode.BarcodeHeight = 2F;
            //  Set image resolution to 300 dpi.
            barcode.Resolution = 300;

            //  Set all margins to 0
            barcode.LeftMargin = 0;
            barcode.RightMargin = 0;
            barcode.TopMargin = 0;
            barcode.BottomMargin = 0;

            Bitmap qrcodeBitmap = barcode.ToImage();
            qrcodeBitmap.Save(@"W:\Projects\Test-Output\RasterEdge.com\barcode-data-matrix-international-byte.png");






How to create Data Matrix in PDF, Tiff, Word, Image files using C#


To create and insert Data Matrix barcode in PDF, Tiff, Office Word, Excel, PowerPoint, and JPG, BMP raster images, please try the following C# sample source codes:





Create Data Matrix with advanced options using C#

Data Matrix Format Mode in C#

Data Matrix ISO standard specifies 24 square symbols and 6 rectangular symbols available in ECC 200. Each symbol size includes different rows and columns with different data storage capacity. You can view the details here: Data Matrix ECC 200 symbol attributes

Using C# Data Matrix Barcode library, you can create and customize Data Matrix barcode with specified size format in C# code.
  • Set property FormatMode to specify the generated Data Matrix size format mode.
DataMatrix barcode = new DataMatrix();
barcode.FormatMode = DataMatrixFormatMode.Format_48X48;




Data Matrix Structured Append mode in C#

Data Matrix barcode standard provides a mechanism for the data in a file to be split into blocks and be represented in more than one Data Matrix barcode symbol.

The following C# codes explain how to store one message into 3 three Data Matrix barcode images using C# Barcode Generator library.
  • Set property StructuredAppend to true to enable Data Matrix Structured Append mode
  • Set property SymbolCount to specify the total number of Data Matrix barcodes to store the same data message
  • Set property SymbolIndex to specify the order of the current data matrix. The first symbol index should be starting with 0
  • Set property FileId with a random unique integer. All data matrix barcodes to store the same data message should have the same FileId value.
DataMatrix barcode = new DataMatrix();
barcode.Data = "Data Matrix";
barcode.StructuredAppend = true;
barcode.SymbolCount = 3; // The whole data message will be stored in three Data Matrix barcodes
barcode.SymbolIndex = 0; // This Data Matrix is the first one
barcode.FileId = 999;
barcode.drawBarcode("C://Output//csharp-datamatrix-structured-append-demo.png");




Data Matrix FNC1 in the first position in C#

When FNC1 appears in the first Data Matrix symbol character position, it shall signal that the Data Matrix encoding data conforms to the GS1 Application Identifier standard format.

To enable this mode using C# Data Matrix barcode generator library, you need apply the following property in the C# source code.
  • Set property FNC1 with value FNC1.FNC1_1ST_POS
DataMatrix barcode = new DataMatrix();
barcode.FNC1 = FNC1.FNC1_1ST_POS;








Common Asked Questions

What is a Data Matrix code?

A Data Matrix code is a 2D barcode. It's a compact 2D barcode made up of a pattern of black and white "cells" or modules arranged in a square.

Using XImage Data Matrix Generator C# library, you will create and print ISO standard and GS1 standard data matrix in C# ASP.NET Core, MVC, WinForms, Console, WPF apps.

What's the ISO standard for Data Matrix codes?

The international standard that defines ISO specification for Data Matrix is ISO/IEC 16022. Its latest version is ISO/IEC 16022:2024. XImage Data Matrix Generator C# library fully support ISO/IEC 16022. And you can quickly create ISO standard Data Matrix in C# Visual Studio .NET projects.

What are the various types of Data Matrix?

Based on the latest ISO specification for Data Matrix, there are two versions: ECC 000-140 and ECC 200. ECC 200 is the recommended version suggested by ISO. XImage Data Matrix Barcode Generator C# library fully supports ECC 200 data matrix generation in C# class.

What's the data storage capacity of a Data Matrix?

The amount varies with the data format:
  • Numeric only: Up to 3,116 digits
  • Text and numbers: Up to 2,335 characters
  • Binary/byte data: Up to 1,555 characters
C# Data Matrix generation library supports the above data matrix data format and data length in C#.NET apps.

What are the minimum and maximum sizes of a Data Matrix barcode?

The smallest size of a Data Matrix barcode is 10 x 10 modules. The largest size is 144 x 144 modules. C# Data Matrix generator library supports all module sizes defined in Data Matrix ISO standard.

Can a phone scan a Data Matrix code?

Absolutely. Most smartphones can scan Data Matrix codes; you just need to install a third-party scanning app from the Google Play Store or Apple App Store that supports the Data Matrix format. You can also use free barcode scanner software developed by RasterEdge C# Barcode Reader library.

Are Data Matrix and QR Code the same?

No, they are different barcode types. However, both are 2D barcodes that can encode text and data, for example, they can encode ASCII text, Unicode text, and binary data, and both are used to encode GS1 business data messages. Using XImage.Barcode Generator C# library, you are able to generate both Data Matrix and QR Code barcodes in C# ASP.NET, MVC, .net core and .net framework web applications.