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

C# Imaging - Read Data Matrix in C#.NET


Data Matrix Barcode Reading from Document Image File Using C#. Support Read barcode from PDF in C#.




C# Imaging - Data Matrix Reading from Document & Image



C#.NET Barcode Reader Add-on from RasterEdge DocImage SDK for .NET successfully combines advanced Data Matrix barcode detecting & reading functions with mature C#.NET document image processing technologies. This .NET Framework-oriented barcode scanning & decoding control, SDK, toolkit can easily & accurately read & decode Data Matrix barcode from scanned documents (like PDF, Word, Excel & PowerPoint) and raster image files (like png, tiff & gif) in both ASP.NET web site & Windows class applications using C# code.


Related .net document control helps:
c# asp.net powerpoint viewer: ASP.NET PowerPoint Document Viewer Control (MVC & WebForms): view ppt, pptx files online in C# using ASP.NET
asp.net mvc pdf editor using c#: ASP.NET MVC PDF Viewer & Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
asp.net sharepoint document viewer open source: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint
c# asp.net text file viewer: ASP.NET Text file viewer in MVC, WebForms: Open, view, annotate, convert txt files in C# ASP.NET
asp.net edit pdf text using c#: ASP.NET PDF Text Edit Control: online edit PDF text content using C# ASP.NET
asp.net pdf viewer using c#: ASP.NET PDF Viewer Control: view, navigate, zoom Adobe PDF document in C# ASP.NET
asp.net mvc excel viewer: ASP.NET Excel Viewer in C# Control (MVC & WebForms): view Office Excel document in web browser.


Data Matrix is a commonly-used 2D barcode type. It consists of black & white modules which are grouped in a square or rectangular pattern. Similar to other 2d barcodes, Data Matrix barcode can store huge information with a small printout barcode size. Besides, Data Matrix also owns strong error correction levels, which makes Data Matrix barcode readable even when the barcode damage has been up to 60%.


There are many factors that affect the recognition & reading of Data Matrix barcode from document image file in .NET class application, like quiet zone width of Data Matrix and resolution of generated Data Matrix barcode image. Besides barcode reading functions, RasterEdge DocImage SDK for .NET also supports fast Data Matrix barcode generation in VB.NET class application.




C# Imaging - Data Matrix Barcode Reader Control Features



Decode Data Matrix barcode from documents file like PDF, Word, Excel and PowerPoint using C#


Recognize Data Matrix from scanned raster image file, like png, gif & bmp using C#


Read all Data Matrix barcodes from target document image file quickly in C#.NET


Scan Data Matrix barcode from whole page or any defined rectangular area using C#


Free to set the number of Data Matrix needed to be recognized from source file


Return & output scanned Data Matrix values to data string in C#.NET class application


Support other linear & 2d barcode recognition from document image file using C# code




Steps to Read/Scan Data Matrix from Image/PDF/TIFF/Office File



Load an image or a document(PDF, TIFF, Word, Excel, PowerPoint).


Get a Bitmap or BasePage used to decode or read barcode.


Set the barcode reader settings.


Call the following static method in BarcodeReader.cs to read or scan barcode from Bitmap or BasePage.


  public static Barcode[] ReadBarcodes(ReaderSettings settings, BasePage page)


  public static Barcode[] ReadBarcodes(ReaderSettings settings, Bitmap image)


The barcode information will be saved in the array of Barcode object. While, if you read barcodes information from the BasePage failed, you can try as follows:


  Convert BasePage to Bitmap with higher resolution by Calling method ConvertToImage(int resolution) in the BasePage.cs:



            //Convert page to bitmap.
            //The default resolution is 96, if youo set the resolution higher, it will be better to read or scan barcode.
            Bitmap bmp = page.ConvertToImage(192);

            //  read all barcodes in the page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(settings, bmp);

            foreach (Barcode barcode in barcodes)
            {
                Console.WriteLine("Data: " + barcode.DataString);
            }



If you want to have a try, please refer to the following demo codes.


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.




Sample C# Code to Decode Data Matrix from Image File



Add necessary references to your C#.NET project. Right-click the project and select "Add Reference..." to locate and add the following DLLs as project references;


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XImage.BarcodeScanner.dll


Use corresponding namespaces;


  using RasterEdge.XImage.BarcodeScanner;


This C#.NET barcode scanning control supports reading & decoding one or more 2D Data Matrix barcode(s) from several commonly-used raster image file formats, including png, jpeg, bmp, tiff and gif. Using the sample C# code below, you can easily detect & decode all Data Matrix barcodes from png image files in .NET class application.




            Bitmap bmp = new Bitmap(inputDirectory + "Sample_Barcode.png");
            //  config reader setting
            ReaderSettings settings = new ReaderSettings();
            //  define the type of barcode to scan
            settings.AddTypesToRead(BarcodeType.DataMatrix);

            //  read all barcodes in the document
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(settings, bmp);

            foreach (Barcode barcode in barcodes)
            {
                Console.WriteLine("Data: " + barcode.DataString);
            }





C#: DLLs for Data Matrix Barcode Scanning from Document(TIFF, PDF, Office)



In order to run the following demo codes reading Data Matrix from document, the steps as follows are necessary.


Add references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.XImage.BarcodeScanner.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Use corresponding namespaces;


  using RasterEdge.XImage.BarcodeScanner;


  using RasterEdge.Imaging.Basic;




Sample C# Code for Reading Data Matrix from TIFF Image File



With RasterEdge .NET Barcode Reader SDK, users are allowed to reading Date Matrix not only from png, jpeg, bmp and gif image files, but also tiff images. This is the C# demo code for reading Date Matrix from tiff.


Add references(Extra):


  RasterEdge.XDoc.TIFF.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.TIFF;




            // load TIFF document
            TIFFDocument doc = new TIFFDocument(inputDirectory + "Sample_Barcode.tif");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.DataMatrix);

            // read barcode from tiff page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }





Sample C# Code for Data Matrix Barcode Reading from PDF



If you want to read & recognize Data Matrix barcode from scanned PDF document file in C#.NET class application, this barcode reader control will be a great choice. With one line of code, you can detect and decode all the Data Matrix barcodes existing on the target PDF document file. Besides, with the application of X & Y location, you are allowed to define the Data Matrix barcode scanning area.



Add references(Extra):


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.PDF;




            // load PDF document
            PDFDocument doc = new PDFDocument(inputDirectory + "Sample_Barcode.pdf");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.DataMatrix);

            // read barcode from PDF page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }





Sample C# Code to Recognize Data Matrix from Word in .NET



Data Matrix barcode reading from Word works in the same way with that from PDF document. You can also detect and recognize all the Data Matrix barcodes from target Word page within a single line of code and return the decoded barcode values to data string. Similarly, if the Data Matrix barcode(s) needed to be decoded is located in a fixed area, you can use X & Y location to set the barcode scanning area using C# code.



Add references(Extra):


  RasterEdge.XDoc.Word.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.Word;




            // load Word document
            DOCXDocument doc = new DOCXDocument(inputDirectory + "Sample_Barcode.docx");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.DataMatrix);

            // read barcode from Word page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }





Scan Data Matrix Barcode on Excel Document in C#.NET



Following C#.NET sample code is for decoding and scanning 2d Data Matrix barcode from Excel document. Users are still able to program highly user-defined Data Matrix scanning project by calling and specifying barcode reading APIs and methods.



Add references(Extra):


  RasterEdge.XDoc.Excel.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.Excel;




            // load Excel document
            XLSXDocument doc = new XLSXDocument(inputDirectory + "Sample_Barcode.xlsx");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.DataMatrix);

            // read barcode from Excel page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }





Demo C# Code on Decoding Data Matrix from PPTX Document



Besides Microsoft Word document, RasterEdge .NET Imaging Barcode Reader still allows users to detect and decode 2d Data Matrix from MS PowerPoint document. The target barcode can be read no matter it is in which page or which certain area of the desired PPTX page.



Add references(Extra):


  RasterEdge.XDoc.PowerPoint.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.PowerPoint;




            // load PowerPoint document
            PPTXDocument doc = new PPTXDocument(inputDirectory + "Sample_Barcode.pptx");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.DataMatrix);

            // read barcode from PowerPoint page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }