KA.Barcode for .NET Suite
How to Generate, Print Data Matrix in C#.NET
How to Generate 2D Data Matrix Barcode Images Using Visual C# in .NET Applications

C# Data Matrix Barcode Generator Library
Generate, create, render data matrix 2d barcode from string data with free open source c# example. no font









  • Completely compatible with .NET Framework 2.0 and later versions
  • Easy to generate Data Matrix ECC 200 barcodes in Visual C#.NET programming
  • Dynamically generating Data Matrix in ASP.NET, WinForms, Crystal Reports and RDLC Reports
  • Draw Data Matrix barcode images in stream & graphics object and save in multiple image formats
  • Offer various barcode settings for Data Matrix including module width, format mode, margins, etc
  • Puchase royalty-free and permanent license of .NET Data Matrix Barcode Generator Library
This guide helps you implement Data Matrix barcode generation across VB.NET projects, WinForms desktop apps, WPF applications, and ASP.NET MVC platforms using C#. You will explore complete encoding, customization, and deployment workflows for professional .NET development.

C# Data Matrix Barcode Control Description
KA.Barcode for .NET Suite is a mature and reliable barcoding encoder control SDK for generating two-dimensional Data Matrix images in .NET development environment. Developers can easily create and display Data Matrix in ASP.NET web pages, Windows Forms & Crystal Reports with C# programming. Flexible barcode settings are also available for users to customize generated images.
What Is A Data Matrix Barcode
Data Matrix, also named as ECC200, 2D DataMatrix barcode, is a two-dimensional matrix barcode commonly used to mark small items. Being space-efficient, Data Matrix is recommended by American EIA for labeling small electronic components.

Data Matrix in ASP.NET projects

This KeepAutomation barcode encoder dll for .NET also supports Data Matrix barcode generation in ASP.NET web applications. Users can easily create Data Matrix barcodes in Websites, Microsoft IIS as well as Visual C# Class Library & Console applications. Here are more details for you:
How to print barcode in Visual C# with ASP.NET framework web control.
Create barcodes in ASP.NET Core web app using C#
Create barcodes in ASP.NET Core MVC web app using C#

Data Matrix in .NET Windows (Desktop) projects

With KeepAutomation barcode generator for .NET Suite, developers can easily create Data Matrix barcodes in .NET Windows Forms with simple control drag-n-drop or C# class library. For more details or C# sample code, please view
How to create barcode in .NET WinForms with Visual C#.
Generate barcodes in WPF .NET Core using C#




Data Matrix Valid Data Sets
  • All 128 characters of ASCII.

  • Extended ASCII (ISO 8859-1 values 128-255)
Create GS1 Compatible Data Matrix
  • Set FNC1 to KeepAutomation.Barcode.FNC1.First

  • In barcode data setting CodeToEncode, around AI code with "()", and followed by AI data, such as "(02)225(03)33344". Here "02", "03" are the AI code, "225", "33344" is the AI data,





Encode Non-printable Chars in Data Matrix
  • Set TildeEnabled to true

  • Use '~ddd' for non-printable chars. For example, ASCII char [GS] is non-printable, and its decimal value is 29. In barcode data, you need use ~029 for char [GS].




Encode byte[] in Data Matrix
The following C# source codes demo how to encode byte[] object in Data Matrix
//  Byte array to encode
byte[] dataBytes = new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45 };

//  Convert byte array to the input (property CodeToEncode)
String inputMsg = "";
foreach (byte b in dataBytes)
    inputMsg += "~" + b.ToString().PadLeft(3, '0');

//  Create barcode
BarCode barcode = new BarCode();
barcode.Symbology = Symbology.DataMatrix;
barcode.DataMatrixDataMode = DataMatrixDataMode.Base256;
//  enable '~' in the input message
barcode.TildeEnabled = true;
barcode.CodeToEncode = inputMsg;

//  set module size to 5 pixels
barcode.BarcodeUnit = BarcodeUnit.Pixel;
barcode.X = 5;
barcode.Y = 5;

barcode.generateBarcodeToBitmap().Save(@"C:\DataMatrix_Bytes.png");




Encode Japanese (non-English) text in Data Matrix
The following C# source codes demo how to encode non English text (such as Japanese text) in Data Matrix
//  Message in Japanese
String unicodeMsg = @"おはようございます";

//  Convert Unicode string to data bytes
byte[] dataBytes = Encoding.Unicode.GetBytes(unicodeMsg);
//  Convert byte array to the input (property CodeToEncode)
String inputMsg = "";
foreach (byte b in dataBytes)
    inputMsg += "~" + b.ToString().PadLeft(3, '0');

//  Create barcode
BarCode barcode = new BarCode();
barcode.Symbology = Symbology.DataMatrix;
barcode.DataMatrixDataMode = DataMatrixDataMode.Base256;
//  enable '~' in the input message
barcode.TildeEnabled = true;
barcode.CodeToEncode = inputMsg;

//  set module size to 5 pixels
barcode.BarcodeUnit = BarcodeUnit.Pixel;
barcode.X = 5;
barcode.Y = 5;

barcode.generateBarcodeToBitmap().Save(@"C:\DataMatrix_Japanese.png");






Generate Barcode Image in Specified Width and Height
  • Set property AutoSizeAdjust to true

  • Set property DPI to be the same or higher as your printer's resolution

  • Set property BarcodeUnit to inch or cm

  • Set property BarCodeWidth and BarCodeHeight to your required image width and height
Data Matrix Property Settings
Click to view the complete list of properties for Data Matrix generation at Data Matrix generator property list for C#.NET code
Data Matrix Barcode Generation in .NET Applications with C#


Data Matrix Character Encoding in C#

Valid Encoding Character Sets

Data Matrix supports multiple character sets for global .NET applications:
  • Full ASCII (all 128 standard characters)
  • Extended ASCII (ISO 8859-1, values 128 - 255)
  • Unicode for international languages (Arabic, Cyrillic, Greek, Hebrew) via ECI protocol


Maximum Data Length

Capacity varies by encoding mode:
  • Alphanumeric: up to 2,335 characters
  • Byte data (8-bit): up to 1,555 characters
  • Numeric data: up to 3,116 digits


Data Matrix Encoding Modes

Six encoding modes are available. The library can auto-select the best mode for your data.

Full mode list:
  • DataMatrixDataMode.ASCII: for digits and standard ASCII
  • DataMatrixDataMode.C40: for uppercase alphanumeric data
  • DataMatrixDataMode.Text: for lowercase alphanumeric data
  • DataMatrixDataMode.X12: for ANSI X12 EDI datasets
  • DataMatrixDataMode.Edifact: for ASCII 32 - 94
  • DataMatrixDataMode.Base256: for full byte values 0 - 255


Advanced Data Encoding Using C#

This section covers special Data Matrix encoding for WinForms, WPF, and VB.NET applications.


Encode Non-Printable Characters

Non-printable ASCII characters (like carriage return) can be encoded using the tilde ~ format.
  • Set ProcessTilde = true
  • Set DataMode = DataMatrixDataMode.Base256
  • Encode characters as ~ + 3-digit ASCII value (e.g., ~013 for [CR])
Note: Incorrect 3-digit formatting will cause failed encoding. Double-check values before running.


Encode Unicode Text

You can encode Unicode text for multi-language support in WPF and WinForms apps.
  • Create a DataMatrix object
  • Assign Unicode text to the Data property
  • Set EncodeUnicodeText = true
  • Export to image file or Stream object
Additional Supported Formats. You may also implement these advanced features:
  • Binary data encoding
  • GS1 business message encoding
  • Structured Append mode for large datasets


Data Matrix Barcode Dimension & Size Settings in C#

Customize Data Matrix barcode size for UI design in WinForms, WPF, and printed documents.


Square Data Matrix

  • Create DataMatrix object
  • Set BarcodeWidth to define pixel size (height matches width)


Rectangular Data Matrix

Data Matrix ECC200 supports 6 fixed rectangular formats. Maintain width/height ratio matching the symbol's row/column ratio.

Supported formats:
  • 8×18
  • 8×32
  • 12×26
  • 12×36
  • 16×36
  • 16×48


Advanced Size Configuration

You can fine-tune dimensions using these properties:
  • UOM: Unit of measure (PIXEL, CM, INCH)
  • X: Module width (smallest barcode element)
  • LeftMargin, RightMargin, TopMargin, BottomMargin: Quiet zone borders
  • AutoResize: Automatic image scaling
  • Resolution: Output DPI for printing
Note: If data exceeds symbol capacity, the library automatically selects a larger format.


Data Matrix Color & Image Options in C#

Customize appearance for WinForms/WPF themes and printing requirements.


Color Customization

Standard Data Matrix colors are dark barcode on light background. Inverted (light on dark) is also supported. Custom colors (e.g., red) may require scanner compatibility.



Image Format Export

Export to raster and vector formats:
  • JPEG, PNG, BMP: use ImageFormat property
  • SVG: use drawBarcode2SVG()
  • EPS: use drawBarcode2EPS()








Frequently Asked Questions

What does a Data Matrix code refer to?

A Data Matrix is a two-dimensional barcode format. It consists of black and white cells, typically set out in a square pattern and hold a substantial amount of information in a small space. Using C# Data Matrix Barcode Generator library, you can quickly create, print Data Matrix barcodes in C# ASP.NET, MVC, Web Forms, .NET Core, framework, WinForms, and WPF applications.

What is the ISO standard for Data Matrix?

The specification for Data Matrix barcodes is standardized under ISO/IEC 16022. The most recent version of this standard is ISO/IEC 16022:2024. C# Data Matrix Generation library supports creating and printing ISO standard Data Matrix and GS1 standard Data Matrix in Visual Studio .NET projects.

What different kinds of Data Matrix are there?

The latest ISO specification for Data Matrix defines two versions: ECC 000-140, and ECC 200. ECC200 is Data Matrix recommend version, and C# Data Matrix Barcode Generation SDK supports ECC 200 in C# class.

How much data can fit in a Data Matrix code?

It depends on the data format used for encoding the Data Matrix.
  • Alphanumeric data: Up to 2,335 characters.
  • Byte data (8-bit): Up to 1,555 characters.
  • Numeric data: Up to 3,116 digits.
Using C# Data Matrix Barcode Generator library, you will encode and make Data Matrix with maximum data length in C# ASP.NET Core, MVC, Blazor web applications.

What are the size limits for a Data Matrix barcode?

A Data Matrix code can range from a small 10x10 grid to a large 144x144 grid of modules (the individual black and white squares). Data Matrix C# library fully supports all defined size modes in ISO standard in C# console, Windows Forms, WPF desktop applications.

Is it possible to scan a Data Matrix with a phone?

Yes. For iPhones, you can scan a Data Matrix by installing a third-party app. KeepAutomation also provides C# Barcode Reader library to read, scan Data Matrix codes from images.

Is a Data Matrix the same as a QR Code?

No, they are separate types of 2D barcodes. They do have several similarities and share common capabilities: both are 2D barcodes, support encoding ASCII text, Unicode text, and binary data, and both can encode GS1 business data messages; but are visually different and use different encoding standards. Using C# Barcode Generator library, you can easily create and print both QR Code and Data Matrix 2d barcodes in C# ASP.NET, mvc web applications.