barcodelib.com Home
  Contact Us  |   Purchase  
Google
BarcodeLib.com Home > Products > Barcode for Java > Barcode Data Matrix


Data Matrix Barcode for Java, J2EE, JasperReports

It is also known as Data Matrix, ECC200.

Quick Navigate
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.
DataMatrix is being used to encode product and serial number information on electrical rating plates; to mark of surgical instruments in Japan; to identify lenses, circuit boards, and other items during manufacturing.
Barcode Library supports all DataMatrix Formats and the data represented in the symbol can be compressed using one of following algorithms.
  • ASCII (0): it is used to encode data that mainly contains ASCII characters (0-127). This is the default encoding format by Barcode Library.
  • C40 (1): it is used to encode data that mainly contains numeric and upper case characters.
  • Text (2): it is used to encode data that mainly contains numeric and lower case characters.
  • Base256 (3): it is used to encode 8 bit values.

Sample of a DataMatrix Barcode
Data Matrix Barcode for Java supports:
  • all 128 characters of ASCII

The following code illustrates how to create a barcode in a Java class

1            DataMatrix barcode = new DataMatrix(); 
2            barcode.setData("123456789"); 
4            barcode.createBarcodeImage("c:/datamatrix.gif"); 


  • Create a DataMatrix object (line 1)
  • set DataMatrix object properties (line 2)
  • save into gif file (line 4)

There are two ways to create barcode images in your Java web applications.

  1. This is the simplest way to stream barcode image using our provided barcode servlet classes.

    And it will not save barcode images in your server side.

    • Under demo package, copy barcode folder to your java servlet container like tomcat.

    • To test your installation, goto http://YourDomain:Port/barcode/datamatrix?Data=123456789

    • To create barcode image in your JSP page, you can pass the url to IMG tag src value. For example, <img src="http://YourDomain:Port/barcode/datamatrix?Data=123456789" />

  2. The second method is similar with the way to generate barcode in Java applications.

    • Create a barcode image in server side

      1            DataMatrix barcode = new DataMatrix(); 
      2            barcode.setData("123456789"); 
      4            barcode.createBarcodeImage("C:/Tools/Tomcat 5.5/webapps/YourWebApp/bimages/datamatrix.gif"); 
      
      
      

    • In your JSP page, you can using IMG tag to display generated image, like <img src="http://YourDomain:Port/YourWebApp/bimages/datamatrix.gif" />

The following jasper xml content illustrates how to insert a barcode into JasperReports

<import value="com.barcodelib.barcode.BarcodeFactory"/> 

Import class BarcodeFactory to report.

 
<imageExpression class="net.sf.jasperreports.engine.JRRenderable"> 
    <![CDATA[new com.barcodelib.barcode.BarcodeJasperRenderer( 
        BarcodeFactory.createDataMatrix("0470821632", 2, 0))]]> 
</imageExpression>

Please go to class BarcodeFactory in Java doc for all methods to create Data Matrix barcode.

Developers also can extend BarcodeFactory class to meet their own requirements. Complete BarcodeFactory.java Source Code

Just call DataMatrix object method createBarcodeImage, e.g. barcode.createBarcodeImage("c:/datamatrix.gif");
Category Attribute/Method Servlet Attribute Default Value Description
Basic Settings
data Data "" This is the barcode text to be encoded. The type is String.
format Format DataMatrix.FORMAT_10X10 (0) Valid values are from 0 to 29.
encoding Encoding AUTO (4) 5 Valid Options: ASCII (0), C40 (1), TEXT (2), BASE256 (3), AUTO (4)
processTilde ProcessTilde true Set the ProcessTilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default is true. ~NNN: is used to represent the ASCII character with the value of NNN.
Image Size and Style
uom UOM 0 (pixel) Unit of measure for barcode size settings, type is float, default is 0 (pixel). Valid values are 0 (pixel), 1 (CM), 2 (Inch)
resolution Resolution 96 Image resolution. Default is 96 DPI.
moduleSize ModuleSize 1 Set the moduleSize property for bar cells width. This value will decide the whole barcode image width and height. Its unit of measure is decided by uom.
leftMargin LeftMargin 0 Image left margin. Its unit of measure is decided by uom.
rightMargin RightMargin 0 Image right margin. Its unit of measure is decided by uom.
topMargin TopMargin 0 Image top margin. Its unit of measure is decided by uom.
bottomMargin BottomMargin 0 Image bottom margin. Its unit of measure is decided by uom.






   Copyright 2008 BarcodeLib.com. Provides High Quality Barcode Data Matrix for Java, Barcode Data Matrix for JasperReports Library. All rights reserved.