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();

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();

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: