Royalty-free developer license, one time purchase for lifetime use
Java Data Matrix Introduction
Data Matrix is also known as Data Matrix, ECC200.
Compatibility: Barcode for Java library is compatible with the latest Data Matrix ISO specification [ISO/IEC 16022 (Second edition 2006-09-15)].
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.
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.
Sample of a DataMatrix Barcode
Java Data Matrix Encoding Data Scope
Data Matrix Barcode for Java supports:
all 128 characters of ASCII.
values 128-255 in accordance with ISO 8859-1. There are referred to as extended ASCII.
How to Generate Data Matrix Barcode in Java Class?
The following Java code illustrates how to create a Data Matrix barcode, and output to various formats.
1 DataMatrix barcode = new DataMatrix(); 2 barcode.setData("DATA MATRIX");
// add more Data Matrix property settings here 3 barcode.renderBarcode("c:/barcode.gif");
Generate data matrix barcode and encode into gif image format (line 3)
Generate data matrix and output to BufferedImage object (line 4)
Generate data matrix in bitmap and output to byte[] (line 5)
Generate data matrix and draw to defined area (Rectangle2D) on Graphics2D (line 6-8)
Generate data matrix and output to OutputStream (line 9-10)
Print Data Matrix in Java Memory
If you need to create a Data Matrix barcode in Java memory for further processing, the Java barcode generator library provides several methods. For example, output can be directed to an OutputStream:
How to create Data Matrix with text in Java?
Data Matrix barcodes support encoding:
All 128 ASCII characters
Values 128–255 in accordance with ISO 8859 1 (extended ASCII)
Unicode text
Binary data
Convert ASCII String to Data Matrix
Encoding plain ASCII text to Data Matrix is straightforward. Input the ASCII text string using the setData() method.
Encode ASCII Non Printing Characters
The full ASCII table contains 33 control characters (non printing), such as carriage return (CR). These cannot be typed directly in a Java IDE code editor. Using the Java Barcode Generator library, you can encode them using their ASCII values.
Enable tilde processing with setProcessTilde(true).
Convert each non printing character's ASCII code to a three digit format prefixed with ~. For example, CR (ASCII 13) is represented as ~013.
Convert Unicode Text to Data Matrix
Data Matrix supports Unicode text encoding. To encode Unicode text in a Java program:
Create a DataMatrix object.
Set the Unicode text using setData(). In the example below, the Japanese text “東京” is encoded.
Enable Unicode text encoding with setEncodeUnicodeText(true).
Print the Data Matrix to an image file.
Encode GS1 Data Messages
Data Matrix supports the GS1 standard. To create a GS1 Data Matrix barcode in Java:
Enable FNC1 (Function 1) using setFnc1Mode(IBarcode.FNC1_ENABLE).
Input the GS1 Application Identifier (AI) code and data in setData().
Print the GS1 Data Matrix barcode.
How to Create and Adjust Data Matrix Dimension Size in Java
Using the BarcodeLib Java Barcode library API, you can create a Data Matrix with custom image width and height in your Java application.
Data Matrix in Square Shape
Most Data Matrix barcodes are square. When generating a square Data Matrix, you only need to set the barcode width; the library automatically produces a square image with equal width and height.
Data Matrix in Rectangle Shape
The Data Matrix (ECC200) standard defines six rectangular symbol sizes with the following row and column counts:
8 rows × 18 columns
8 rows × 32 columns
12 rows × 26 columns
12 rows × 36 columns
16 rows × 36 columns
16 rows × 48 columns
To generate a rectangular Data Matrix, ensure the image width to height ratio matches the columns to rows ratio. The following example creates a Data Matrix with 16 rows and 48 columns:
Use setFormatMode(DataMatrix.F_16X48) to specify the symbol size.
Set the barcode width to 300 pixels and height to 100 pixels.
Create Data Matrix with Advanced Features Using Java
Data Matrix Format Mode
The Data Matrix ISO standard specifies 24 square and 6 rectangular symbol sizes available in ECC 200. Using the Java Data Matrix Barcode Generator library, you can specify a particular size format via the FormatMode property.
Data Matrix Structured Append Mode
With the Java Data Matrix Generation SDK, you can split a large data message across multiple Data Matrix barcodes. The following Java code demonstrates storing a single message in three Data Matrix images.
Set StructuredAppend to true to enable Structured Append mode.
Set SymbolCount to the total number of barcodes that will store the same data message.
Set SymbolIndex to the order of the current barcode (starting at 0).
Set FileId to a random unique integer; all barcodes sharing the same data message must have the same FileId.
Data Matrix FNC1 in the First Position
When creating a Data Matrix with GS1 data encoded in a Java program, the FNC1 character must appear in the first symbol character position. To enable this mode using the Java Data Matrix barcode generator library, set the FNC1 property to FNC1.FNC1_1ST_POS.
Java Data Matrix Property Settings
Set the data property with the value to encode. Type is String. Servlet URL Parameter: "Data".
Set the dataMode property. Valid value is DataMatrix.MODE_AUTO (default), DataMatrix.MODE_ASCII, DataMatrix.MODE_C40, DataMatrix.MODE_TEXT, DataMatrix.MODE_X12, DataMatrix.MODE_EDIFACT, DataMatrix.MODE_BASE256. Servlet URL Parameter: "DataMode". Sample: &DataMode=1
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.
Set the format property. Type is int. Default is DataMatrix.FORMAT_10X10. Specifies the Data Matrix Format to use on that symbology. Valid values see class DataMatrix.FORMAT_*x*; Servlet URL Parameter: "Format". Sample: &Format=0.
Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the encoding data. Default is false. Servlet URL Parameter: "ProcessTilde". Value: "t" (true), "f" (false). Sample: &ProcessTilde=t. Format of the tilde:
~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.
~6NNNNN: is used to represent the Unicode. NNNNN is from 00000 - 65535.
~rp: is used only at the very beginning of the symbol for the reader programming purpose.
~m5: is used only at the very beginning of the symbol, the header [)> + ASCII 30 + ASCII 05 + ASCII 29 will be transmitted by the barcode reader before the data in the message and the trailer ASCII 30 + ASCII 4 will be transmitted afterwards.
~m6: is used only at the very beginning of the symbol, the header [)> + ASCII 30 + ASCII 06 + ASCII 29 will be transmitted by the barcode reader before the data in the message and the trailer ASCII 30 + ASCII 4 will be transmitted afterwards.
~7NNNNNN: is used to specify the Extended Channel Interpretations and NNNNNN is a value between 000000 and 999999.
Data Matrix can be divided into multiple data areas. Conversely, information stored in multiple Data Matrix symbols can be reconstructed as single data symbols.One data symbol can be divided into up to 16 symbols.
SetisStructuredAppend property to true, then Structured Append is enabled. Servlet Parameter: "IsStructuredAppend".
Set symbolCount property to the number of total symbols which make the sequence. Servlet Parameter: "SymbolCount".
Set symbolIndex property to the position of current symbol in the secuence (Start with 0). Servlet Parameter: "SymbolIndex".
Set fileID property to be identified to the same file. Servlet Parameter: "FileID".
Set the fnc1Mode property. Servlet URL Parameter: "FNC1Mode". Sample: &FNC1Mode=0.
0 (none)
1 (enabled)
Setting up barcode image size.
Set property uom (Unit of Measure) for properties X, Y, leftMargin, rightMargin, topMargin and bottomMargin. Default is Linear.UOM_PIXEL (0). Valid values are Linear.UOM_PIXEL (0), Linear.UOM_CM (1), Linear.UOM_Inch (2). Servlet URL Parameter: "UOM". Value: 0 (pixel), 1 (cm), 2 (inch). Sample: &UOM=0.
Set the moduleSize (for barcode module width & height) property. Type is float. Default is 5. Servlet URL Parameter: "ModuleSize". Sample: &ModuleSize=5.
Set the leftMargin, rightMargin, topMargin and bottomMargin properties, and types are all float. Default values are 0 for all 4 margin settings. Servlet URL Parameter: "LeftMargin", "RightMargin", "TopMargin", "BottomMargin". Sample: &LeftMargin=0.
Set the resolution property (Value is expressed in DPI - Dots per inch). Default is 72 dpi. Servlet URL Parameter: "Resolution". Sample: &Resolution=72.
With rotate property, you can display barcode horizontally or vertically. Default value is 0. Servlet URL Parameter: "Rotate". Sample: &Rotate=0. Value can be:
0 (Linear.ANGLE_0),
1 (Linear.ANGLE_90),
2 (Linear.ANGLE_180),
3 (Linear.ANGLE_270).
How to Set Generated Barcode Data Matrix Image Size?