Java Barcode Libraries  >  Java Barcode  >  Java Barcode Generation Guide  >  Java Data Matrix Generator for Java Class


Java Data Matrix Generator


Barcode DataMatrix Generation in Java Class, Jasper Reports, iReport, BIRT

Java Barcode offers the most affordable Java barcode generator for barcode Java professionals.


Java Data Matrix Introduction


Data Matrix is also known as Data Matrix, ECC200.

DataMatrix is a two-dimensional (2D) barcode symbology which can store from 1 to about 2,000 characters.
DataMatrix ECC200 version supports advanced encoding error checking and correction algorithms (reed-solomon). Those algorithms allow the recognition of barcodes that are up to 60% damaged.


Java Barcode Data Matrix Generator - How to generate barcode Data Matrix in Java Class?

The following Java code illustrates how to generate a barcode in Java class:

DataMatrix barcode = new DataMatrix(); 

// set barcode properties
barcode.setCodeText("Data Matrix"); 
  
// draw and generate barcode to buffered image object
BufferedImage datamatrixImage = barcode.drawBarCode2Image();


Java Barcode Data Matrix Generator - How to generate Data Matrix barcodes to Java Servlet applicatons?

The following Java code illustrates how to generate a barcode in Java Servlet class:

public class BarcodeServlet extends HttpServlet { 
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException 
    { 
        try { 
            DataMatrix barcode = new DataMatrix(); 

            // set barcode properties 
            barcode.setCodeText("Data Matrix");
            
            // draw and generate barcode to response's ServletOutputStream 
            ServletOutputStream servletoutputstream = response.getOutputStream(); 
            
            barcode.drawBarCode2Stream(servletoutputstream); 

        } catch (Exception e) { 
            throw new ServletException(e); 
        } 
    } 
}


Java Barcode Data Matrix Generator - How to create Data Matrix barcodes through HTTP Request

  1. Install Java Barcode Generator Servlet application to Tomcat or JBoss, developers need copy the barcode folder to your Tomcat application folder, and restart the Tomcat.

  2. After Tomcat restarted, open your browser and navigate to http://your_tomcat_url:port/barcode/datamatrix?code-text=DATAMATRIX

  3. You can also insert barcodes in HTML or JSP pages.

    <img src="http://your_tomcat_url:port/barcode/datamatrix?code-text=DATAMATRIX">


Java Barcode Data Matrix Generator - How to draw & print barcode Data Matrix to java.awt.Image Object

The following Java source code shows how to draw & print a barcode in a java.awt.Image object:

private static void demoLinearBarcode() throws Exception 

    DataMatrix barcode = new DataMatrix(); 

    // set barcode properties 
    barcode.setCodeText("Data Matrix"); 

    // create image object 
    java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(300,300,java.awt.image.BufferedImage.TYPE_BYTE_INDEXED ); 
    // get graphic context of image 
    java.awt.Graphics2D imgGraphics = image.createGraphics(); 

    // draw barcode to specified location in Rectangle 
    barcode.paintBarCode(imgGraphics, new java.awt.Rectangle(0, 0, 300, 300)); 
}


Java DataMatrix Properties


Class Properties HTTP Parameters Default Comments
data data "" Barcode value to encode
uom uom PIXEL Unit of meature for all size related settings. 0: pixel; 1: cm; 2: inch. Default is pixel
moduleSize module-size 3 Barcode module width of barcode module, default is 3 pixel
leftMargin left-margin 0 Barcode image left margin
rightMargin right-margin 0 Barcode image right margin
topMargin top-margin 0 Barcode image top margin
bottomMargin bottom-margin 0 Barcode image bottom margin
resolution resolution 72 Barcode image resolution in dpi
rotate rotate 0 Barcode rotate angle, valid values: 0, 90, 180, 270
processTilde process-tilde false Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default is false.
~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.
dataMode data-mode 0 (Auto) Set the dataMode property. Valid value is 0 DataMatrix.MODE_AUTO (default), 1 DataMatrix.MODE_ASCII, 2 DataMatrix.MODE_C40, 3 DataMatrix.MODE_TEXT, 4 DataMatrix.MODE_X12, 5 DataMatrix.MODE_EDIFACT, 6 DataMatrix.MODE_BASE256.
  • Auto (0): Barcode library will decide the best data mode for you.
  • ASCII (1): it is used to encode data that mainly contains ASCII characters (0-127). This is the default encoding format by Barcode Library.
  • C40 (2): it is used to encode data that mainly contains numeric and upper case characters.
  • Text (3): it is used to encode data that mainly contains numeric and lower case characters.
  • X12 (4):it is used to encode the standard ANSI X12 electronic data interchange characters.
  • EDIFACT (5): it is used to encode 63 ASCII values (values from 32 to 94) plus an Unlatch character (binary 011111).
  • Base256 (6): it is used to encode 8 bit values.
formatMode format-mode 0 Default is DataMatrix.FORMAT_10X10. Specifies the Data Matrix Format to use on that symbology. Valid values see class DataMatrix.FORMAT_*x*;
fnc1Mode fnc1-mode 0 (none)
applicationIndicator ai 0
isStructuredAppend structured-append false If true, then Structured Append is enabled.
symbolCount symbol-count 1 Set the number of total symbols which make the sequence.
symbolIndex symbol-index 1 Set the position of current symbol in the secuence (Start with 0).
fileID file-id 0 Set the property to be identified to the same file.







Java Barcode Generator supports most common linear (1d) and matrix (2d) bar code standards, including:

2D Barcodes Code-39 related Code-128 related Code-25 related EAN/UPC related Other Linear Barcodes
Data Matrix

PDF-417

QR-Code

Code-39

Code-93

Code-128

GS1-128/UCC/EAN-128
Code 2 of 5

Interleaved 2 of 5

ITF-14

Identcode

Leitcode

EAN-8

EAN-13

ISBN

ISSN

UPC-A

UPC-E
Codabar

Code-11

POSTNET

PLANET

USPS Intelligent Mail Barcode (OneCode)

RM4SCC

MSI Plessey