C#: Online Guide
How To: Barcode Generator
Data Matrix
Data Matrix
  |  
Home ›› XImage.Barcode Generator ›› C# Barcode Generator: Data Matrix

C# Imaging - Data Matrix Plug-in SDK Control


Generate Data Matrix Barcode Image Using C#.NET Imaging Library




C# Imaging - 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.


Related .net document control helps:
asp.net mvc file viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects
asp.net edit pdf page control: ASP.NET PDF Pages Edit Control: add, remove, sort, replace PDF pages online using C#
asp.net convert pdf control: ASP.NET Convert PDF Control: Convert, export PDF to Word, HTML, Tiff files in C# ASP.NET
asp.net annotate pdf control: ASP.NET Annotate PDF Control: annotate, comment, markup PDF document online using ASP.NET C#
asp.net webforms pdf editor control: ASP.NET WebForms PDF Editor: create, view, edit, annotate, redact PDF file in ASP.NET WebForms application
asp.net excel file viewer: ASP.NET Excel Document Viewer in C# Control: view office excel files online in ASP.NET web applications
asp.net image file viewer: ASP.NET Image Document Viewer Control: view, annotate, redact, convert image files in html web browser


Detailed features are listed below:


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.




C# Code for Customizing Data Matrix Barcode Generation



You can easily generator Data Matrix and save it  to image files/object using this C#.NET barcode generator control. The following steps will show how to create a Data Matrix type barcode encoding numeric data text "123456789" into the image object with XImage.Barcode.Creator.


Add References


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.BarcodeCreator.dll


  System.Drawing.dll


Using Namespaces


  using System.Drawing;


  using RasterEdge.XImage.BarcodeCreator;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.


Please copy the sample code as follow to generator a DataMatrix barcode.




private static DataMatrix CreateBarcode()
        {
            // create a Data Matrix barcode
            DataMatrix barcode = new DataMatrix();
            // encode data into Data Matrix barcode   
            barcode.Data = "123456789";
            barcode.X = 5.0F;// set module size
            // the minimum value for each margin should be equal to X
            barcode.RightMargin = barcode.LeftMargin = barcode.TopMargin = barcode.BottomMargin = barcode.X;
            barcode.Resolution = 96;// set barcode printing resolution   
            barcode.Rotate = Rotate.Rotate0;// set rotation
            barcode.BarcodeHeight = 200;
            barcode.BarcodeWidth = 200;
            barcode.AutoResize = true;

            //convert barcode to a bitmap and save it to image file
            //Bitmap bmp = barcode.ToImage();
            //bmp.Save(@"C:\barcode.bmp");

            return barcode;
        }





C# Imaging - Create Data Matrix Barcode on Images



You can easily draw industry-standard Data Matrix barcode on png, gif, jpeg and bmp image files using this C#.NET barcode generator control. Copy the following C# sample code to your barcode application to create a Data Matrix encoding numeric data text "123456789" onto a sample png image file and then save it to your local disk ("c:/datamatrix.png").




private static void AddBarcodeToImage(DataMatrix barcode)
        {
            REImage image = new REImage(inputDirectory + "Sample.png");
            barcode.DrawBarcode(image, 150F, 150F);
            image.Save(ImageType.PNG, outputDirectory + "Sample_Barcode.png");
        }





C# Imaging - Insert Data Matrix Barcode on Documents



This Barcode Creator Add-on can help .NET developers insert Data Matrix barcode into a certain page of PDF, TIFF, Word, Excel or PPTX document. Besides, with the application of X & Y location, you are also allowed to specify accurate Data Matrix barcode generating area. Here we offer Visual C# example coding to generate Data Matrix on PDF, TIFF, Word, Excel and PowerPoint respectively.



C# Code to Create Data Matrix on PDF



Add References(Extra)


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Using Namespace(Extra)


  RasterEdge.XDoc.PDF;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToPDF(DataMatrix barcode)
        {
            PDFDocument docx = new PDFDocument(inputDirectory + "Sample.pdf");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.pdf");
        }




C# Code to Draw Data Matrix on TIFF



Add References(Extra)


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.TIFF.dll


Using Namespace(Extra)


  RasterEdge.XDoc.TIFF;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToTIFF(DataMatrix barcode)
        {
            TIFFDocument docx = new TIFFDocument(inputDirectory + "Sample.tif");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.tif");
        }




C# Code to Generate Data Matrix on Word



Add References(Extra)


  RasterEdge.XDoc.Word.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.Word;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToWord(DataMatrix barcode)
        {
            DOCXDocument docx = new DOCXDocument(inputDirectory + "Sample.docx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.docx");
        }




Demo Code to Add Data Matrix to Excel in C#



Add References(Extra)


  RasterEdge.XDoc.Excel.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.Excel;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToExcel(DataMatrix barcode)
        {
            XLSXDocument docx = new XLSXDocument(inputDirectory + "Sample.xlsx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.xlsx");
        }




Create Data Matrix to PPTX Slide in C#.NET



Add References(Extra)


  RasterEdge.XDoc.PowerPoint.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.PowerPoint;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToPowerPoint(DataMatrix barcode)
        {
            PPTXDocument docx = new PPTXDocument(inputDirectory + "Sample.pptx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.pptx");
        }