Skip to footer content
USING IRONBARCODE

Data Matrix Generator in C#: Complete Guide with IronBarcode

Data Matrix barcodes are a widely used type of 2D code that can pack a significant amount of encoded data into a small area. This makes them perfect for labeling pharmaceuticals, marking electronic components, or tracking items in inventory management, where space is limited. In this tutorial, you’ll learn how to use IronBarcode to generate Data Matrix barcodes in C#, customize them for your application, and export them into various files and formats.

Get stated with IronBarcode now.
green arrow pointer

What makes Data Matrix barcodes special?

Data Matrix barcodes are 2D symbols that encode data in a grid of black and white dots arranged into rows and columns. Unlike traditional linear barcodes (such as UPC or EAN), they can store up to 2,335 alphanumeric characters or 3,116 numerical digits in a space as small as 10 x 10 modules. Their built-in Reed-Solomon error correction allows them to be accurately read by modern barcode readers and scanners even when up to 30% of the symbol is damaged.

These characteristics make Data Matrix ideal for marking small parts, postal barcodes, and electronic components, as well as labeling in healthcare and logistics centers. The healthcare industry relies on GS1 Data Matrix standards for medication tracking, while manufacturers embed them in their production lines to help identify items worldwide. Because one barcode can hold so much data, they’re now used internationally in industries seeking complete application traceability.

How do I get started with IronBarcode?

First, install IronBarcode through NuGet Package Manager. Open your Package Manager Console and run:

Install-Package BarCode

Data Matrix Generator in C#: Complete Guide with IronBarcode: Image 1 - Image 1 of 5 related to Data Matrix Generator in C#: Complete Guide with IronBarcode

Add image alt text

Or search for "BarCode" by Iron Software in the NuGet Package Manager UI. After installation, add the namespace to your C# file:

using IronBarCode;
using IronBarCode;
Imports IronBarCode
$vbLabelText   $csharpLabel

That's all the setup required. IronBarcode handles all the complex Data Matrix encoding internally, following the ISO/IEC 16022 standard, letting you focus on your application logic. For detailed installation options, check the advanced installation guide.

How do I create my first Data Matrix barcode?

Generating a Data Matrix barcode requires just one line of code with IronBarcode:

// Create a Data Matrix barcode with product information
var myBarcode = BarcodeWriter.CreateBarcode("PROD-12345-2024", BarcodeWriterEncoding.DataMatrix);
// Save as high-quality PNG image
myBarcode.SaveAsImage("product-label.png");
// Create a Data Matrix barcode with product information
var myBarcode = BarcodeWriter.CreateBarcode("PROD-12345-2024", BarcodeWriterEncoding.DataMatrix);
// Save as high-quality PNG image
myBarcode.SaveAsImage("product-label.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This code creates a Data Matrix barcode encoding the text "PROD-12345-2024" and saves it as a PNG image. The BarcodeWriterEncoding.DataMatrix parameter tells IronBarcode to use the Data Matrix format specifically. The resulting barcode automatically uses the ECC200 standard. That’s the modern Data Matrix specification, which includes built-in error correction, ensuring reliable scanning in real-world conditions.

Barcode Output

Data Matrix Generator in C#: Complete Guide with IronBarcode: Image 2 - First barcode output

For immediate use in applications, you can also retrieve the barcode as a bitmap or export it to various formats:

// Get barcode as bitmap for direct display
var barcodeBitmap = myBarcode.ToBitmap();
// Or save as PDF for document integration
myBarcode.SaveAsPdf("barcode-document.pdf");
// Get barcode as bitmap for direct display
var barcodeBitmap = myBarcode.ToBitmap();
// Or save as PDF for document integration
myBarcode.SaveAsPdf("barcode-document.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

What data types can I encode?

Data Matrix supports various data types, making this 2D barcode generator in C# versatile for different applications:

// Encode alphanumeric product codes
var productCode = BarcodeWriter.CreateBarcode("ABC-123-XYZ", BarcodeWriterEncoding.DataMatrix);
// Encode numeric serial numbers
var serialNumber = BarcodeWriter.CreateBarcode("987654321098765", BarcodeWriterEncoding.DataMatrix);
// Encode URLs for product information
var urlCode = BarcodeWriter.CreateBarcode("https://example.com/product/12345", BarcodeWriterEncoding.DataMatrix);
// Encode Unicode text for international applications
var unicodeBarcode = BarcodeWriter.CreateBarcode("製品-2024-東京", BarcodeWriterEncoding.DataMatrix);
unicodeBarcode.SaveAsImage("unicode-datamatrix.png");
// Encode alphanumeric product codes
var productCode = BarcodeWriter.CreateBarcode("ABC-123-XYZ", BarcodeWriterEncoding.DataMatrix);
// Encode numeric serial numbers
var serialNumber = BarcodeWriter.CreateBarcode("987654321098765", BarcodeWriterEncoding.DataMatrix);
// Encode URLs for product information
var urlCode = BarcodeWriter.CreateBarcode("https://example.com/product/12345", BarcodeWriterEncoding.DataMatrix);
// Encode Unicode text for international applications
var unicodeBarcode = BarcodeWriter.CreateBarcode("製品-2024-東京", BarcodeWriterEncoding.DataMatrix);
unicodeBarcode.SaveAsImage("unicode-datamatrix.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Each encoding type optimizes automatically based on your data. Numeric data uses less space than alphanumeric text, while binary encoding handles special characters and Unicode text efficiently. IronBarcode's data matrix generator in C# automatically selects the most efficient encoding mode, ensuring optimal barcode size without manual configuration.

Output

Here, we can see that the four different data types have successfully turned into Data Matrix barcodes.

Data Matrix Generator in C#: Complete Guide with IronBarcode: Image 3 - Data Matrix barcodes created with 4 different data types

How do I customize the appearance?

IronBarcode provides extensive customization options for Data Matrix generation:

// Create barcode with custom styling
var customBarcode = BarcodeWriter.CreateBarcode("CUSTOM-2024", BarcodeWriterEncoding.DataMatrix);
// Set specific dimensions (in pixels)
customBarcode.ResizeTo(500, 500);
// Adjust colors for special label requirements
customBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.DarkBlue);
customBarcode.ChangeBackgroundColor(IronSoftware.Drawing.Color.LightGray);
// Add human-readable text annotation
customBarcode.AddAnnotationTextBelowBarcode("Product: CUSTOM-2024");
// Set margins for proper quiet zones
customBarcode.SetMargins(10);
customBarcode.SaveAsImage("custom-datamatrix.png");
// Create barcode with custom styling
var customBarcode = BarcodeWriter.CreateBarcode("CUSTOM-2024", BarcodeWriterEncoding.DataMatrix);
// Set specific dimensions (in pixels)
customBarcode.ResizeTo(500, 500);
// Adjust colors for special label requirements
customBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.DarkBlue);
customBarcode.ChangeBackgroundColor(IronSoftware.Drawing.Color.LightGray);
// Add human-readable text annotation
customBarcode.AddAnnotationTextBelowBarcode("Product: CUSTOM-2024");
// Set margins for proper quiet zones
customBarcode.SetMargins(10);
customBarcode.SaveAsImage("custom-datamatrix.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

These customizations help match corporate branding or meet specific labeling requirements. The resize function maintains proper module proportions essential for Data Matrix readability, while color changes accommodate special printing processes or material constraints. Proper margins ensure the quiet zones required by barcode scanning best practices.

Data Matrix Generator in C#: Complete Guide with IronBarcode: Image 4 - Custom data matrix output

Can I generate multiple barcodes at once?

Batch generation streamlines creating multiple Data Matrix codes for production runs:

// Generate barcodes for a batch of products
string[] productIds = { "PROD-001", "PROD-002", "PROD-003", "PROD-004", "PROD-005" };
foreach (string id in productIds)
{
    var batchBarcode = BarcodeWriter.CreateBarcode(id, BarcodeWriterEncoding.DataMatrix);
    batchBarcode.ResizeTo(150, 150);
    batchBarcode.AddAnnotationTextBelowBarcode(id);
    // Save with unique filename
    string filename = $"barcode_{id.Replace("-", "_")}.png";
    batchBarcode.SaveAsImage(filename);
}
// Generate barcodes for a batch of products
string[] productIds = { "PROD-001", "PROD-002", "PROD-003", "PROD-004", "PROD-005" };
foreach (string id in productIds)
{
    var batchBarcode = BarcodeWriter.CreateBarcode(id, BarcodeWriterEncoding.DataMatrix);
    batchBarcode.ResizeTo(150, 150);
    batchBarcode.AddAnnotationTextBelowBarcode(id);
    // Save with unique filename
    string filename = $"barcode_{id.Replace("-", "_")}.png";
    batchBarcode.SaveAsImage(filename);
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This is ideal for industries such as logistics or healthcare that require a comprehensive set of labels, each associated with a unique barcode. It reduces costs while ensuring every item can be easily identified and scanned. For web applications, you might instead stamp barcodes directly onto PDF documents or stream them for real-time generation. The async processing capabilities can further optimize performance for large batches.

Data Matrix Generator in C#: Complete Guide with IronBarcode: Image 5 - Batch data matrix barcode creation

Conclusion

IronBarcode makes Data Matrix generation in C# straightforward while providing professional-grade customization options. From simple product codes to complex Unicode text, you can generate industry-standard 2D codes with minimal code snippets. Built-in error correction ensures your barcode can be accurately read by barcode readers, even if part of the symbol is damaged.

Whether you’re working with postal barcodes, QR code alternatives, or linear barcodes like UPC and EAN, IronBarcode supports them all. With features to export into Word, Excel, PDFs, and application software, you can quickly adapt your solution for any company, network, or industry.

Ready to implement a data matrix generator in your C# project? Start with a free trial to explore all features, or visit our comprehensive tutorials for more barcode generation examples. For production deployments, check our licensing options to find the right fit for your project.

NuGet Install with NuGet

PM >  Install-Package BarCode

Check out IronBarcode on NuGet for quick installation. With over 10 million downloads, it’s transforming PDF development with C#. You can also download the DLL.

Frequently Asked Questions

What is a Data Matrix barcode?

A Data Matrix barcode is a type of 2D code that can encode a large amount of data in a small space. It is commonly used in applications where space is limited, such as labeling pharmaceuticals or marking electronic components.

How can I generate a Data Matrix barcode in C#?

You can generate a Data Matrix barcode in C# using IronBarcode, which provides simple code examples for creating ECC200 Data Matrix barcodes and customizing them for various applications.

What are the benefits of using IronBarcode for Data Matrix generation?

IronBarcode offers easy-to-use tools for generating Data Matrix barcodes, allowing for customization and export into various files and formats. It simplifies the process with straightforward code examples.

Can IronBarcode export Data Matrix barcodes to different file formats?

Yes, IronBarcode allows you to export Data Matrix barcodes into various file formats, making it versatile for different application needs.

Is it possible to customize Data Matrix barcodes with IronBarcode?

Absolutely. IronBarcode provides options to customize Data Matrix barcodes to fit your specific application requirements, ensuring they are tailored to your needs.

For what industries are Data Matrix barcodes particularly suitable?

Data Matrix barcodes are particularly suitable for industries like pharmaceuticals, electronic components, and inventory management due to their ability to store significant data in a compact form.

What version of Data Matrix barcodes does IronBarcode support?

IronBarcode supports the ECC200 version of Data Matrix barcodes, which is the most widely used and standardized version.

Why use Data Matrix barcodes over other types of 2D codes?

Data Matrix barcodes are favored for their high data density and ability to be read even if partially damaged, making them ideal for environments where space is limited or conditions are harsh.

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he ...
Read More