How to print Data Matrix barcode in iReport?
Users can follow the guide to print Data Matrix barcodes in iReport. More details view here: how to generate and print barcodes in iReport reprts.
Another method to stream Data Matrix barcodes in iReport using Java Barcode Generator buildin Servlet web application.
Another method to stream Data Matrix barcodes in iReport using Java Barcode Generator buildin Servlet web application.
- Download the evaluation package and unzip
- Create a new report in iReport, and add barcode.jar to report classpath from the downloaded trial package
- Drag an image item in Palette to report
- Click "Cancel" button, in "Select an image file" window
- Right click on the image and edit its "Properties", and set property "Expression Class" to "net.sf.jasperreports.engine.JRRenderable";
- To input Data Matrix barcode data manually, set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(100, "12345", "", "X=2&Y=2"))" - To print Data Matrix with data from database, please set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(com.onbarcode.barcode.jasper.BarcodeGenerator.draw(100, $F{data field} + "", "", "X=2&Y=2"))";
BarcodeGenerator.draw method accepts 4 parameters:
the second is the barcode data to encode, in String,
the last is the barcode settings String. More details about barcode settings string, please check the Data Matrix property table below
Data Matrix Barcode Data Characters Encoding in JasperReport Reports
To generate a valid, scannable Data Matrix in JasperReport reports, it's critical to understand its encoding rules, including valid character sets, maximum data length, and Data Modes. All configurations are completed in the Report Item Property panel of Jaspersoft Studio or iReport Designer.
Data Matrix Valid Encoding Character Set
Data Matrix in JasperReport reports supports a range of character sets, which can be flexibly used with JasperReport's DataSource and Field features for dynamic data binding. The supported character sets are:
- Full ASCII (all 128 characters): This includes standard letters, numbers, symbols, and control characters, making it suitable for most basic encoding needs.
- Extended ASCII (ISO 8859-1 values 128-255): Supports additional characters such as accented letters, which are common in non-English languages.
- Other character sets (e.g., Arabic, Cyrillic, Greek, Hebrew): These can be supported by enabling the Extended Channel Interpretation (ECI) protocol in the Report Item Property panel. This is useful for international reports that require non-ASCII character encoding.
Data Matrix Maximum Data Length Size
The maximum data length a Data Matrix can encode depends on its encoding Data Mode. The JasperReports Library automatically optimizes data storage based on the selected mode, but understanding the limits helps avoid encoding errors. The maximum lengths for common Data Modes are:
- Alphanumeric data: Up to 2,335 characters. This mode is efficient for encoding combinations of letters, numbers, and basic symbols (e.g., product codes, URLs).
- Byte data (8-bit): 1,555 characters. Suitable for encoding Extended ASCII, binary data, or non-ASCII characters (when used with ECI).
- Numeric data: 3,116 digits. This mode has the highest encoding efficiency, making it ideal for large sets of numeric data (e.g., serial numbers, inventory codes).
Data Matrix Encoding Data Mode
Data Matrix uses six encoding modes (schemes) to efficiently encode different types of data. The JasperReports Library can automatically select the optimal mode for you, or you can manually set it in the Report Item Property panel. Here's how to configure Data Mode in Jaspersoft Studio or iReport Designer:
In the Report Item Property panel, set "DataMode" to "DataMatrixDataMode.Auto".Enter your data (static or dynamic via Expression) in the "Data" field.The JasperReports Library will analyze the data and select the most efficient encoding mode.
Note: Manually selecting the wrong DataMode can lead to encoding errors or inefficient data storage. Use "Auto" mode if you're unsure of the data type.
- Select the Data Matrix (Barcode Component) in your JRXML template.
- Open the Report Item Property panel and locate the "DataMode" dropdown.
- Choose the appropriate mode based on your data type. The available modes (and their use cases) are:
- DataMatrixDataMode.Auto: The JasperReports Library automatically selects the best mode based on the input data. This is the recommended setting for most use cases, especially when the data type varies.
- DataMatrixDataMode.ASCII: For encoding double-digit numerics, ASCII values 0-127, and Extended ASCII values 128-255. Use this mode for standard text and basic symbols.
- DataMatrixDataMode.C40: For upper-case alphanumeric characters, as well as lower-case and special characters. This mode is efficient for mixed-case text.
- DataMatrixDataMode.Text: For lower-case alphanumeric characters, as well as upper-case and special characters. Similar to C40 but optimized for lower-case text.
- DataMatrixDataMode.X12: For ANSI X12 EDI (Electronic Data Interchange) datasets. Ideal for supply chain and business-to-business reports.
- DataMatrixDataMode.Edifact: For ASCII values 32-94, specifically designed for EDIFACT (Electronic Data Interchange for Administration, Commerce, and Transport) data.
- DataMatrixDataMode.Base256: For all byte values 0-255. Use this mode for binary data, non-printable characters, or custom character sets.
- Save the JRXML template to apply the DataMode setting.
In the Report Item Property panel, set "DataMode" to "DataMatrixDataMode.Auto".Enter your data (static or dynamic via Expression) in the "Data" field.The JasperReports Library will analyze the data and select the most efficient encoding mode.
Note: Manually selecting the wrong DataMode can lead to encoding errors or inefficient data storage. Use "Auto" mode if you're unsure of the data type.
Advanced Data Encoding in Data Matrix Using Jaspersoft Studio/iReport
In practical report design, you may need to encode complex data types into Data Matrix, such as non-printable characters, Unicode text, binary data, or GS1 data elements.
Encode Non-Printable Chars in Data Matrix
Some ASCII characters are non-printable (e.g., Carriage Return [CR], Line Feed [LF]) and cannot be directly entered via keyboard. To encode these in Data Matrix, you'll need to use a specific format and configure the appropriate properties in the Report Item Property panel.
- Select the Data Matrix and open the Report Item Property panel.
- Set the "ProcessTilde" property to "true". This enables the use of "~" to represent non-printable characters (formatted as "~ddd", where "ddd" is the three-digit ASCII value).
- Set the "DataMode" property to "DataMatrixDataMode.Base256". This mode supports encoding all byte values, including non-printable characters.
- In the "Data" field, enter the non-printable character in the format "~ddd". For example, to encode [CR], enter "Data~013Matrix" (inserts [CR] between "Data" and "Matrix").
- If using dynamic data, use an Expression (e.g., "$F{NonPrintData}") where the Field stores the formatted string (e.g., "Data~013Matrix").
- Save the JRXML template to apply the settings.
Encode Unicode Text in Data Matrix
You can easily encode Unicode text (e.g., Arabic, Chinese, Cyrillic) into Data Matrix in JasperReport reports using the Report Item Property panel. This is useful for international reports that require non-ASCII text encoding.
- Select the Data Matrix and open the Report Item Property panel.
- Locate the "EncodeUnicodeText" property and set it to "true". It enables the JasperReports Library to encode Unicode text from the "Data" field.
- Enter the Unicode text into the "Data" field. For dynamic data, use an Expression like "$F{UnicodeData}" to reference the Field storing the text.
- Set the "DataMode" to "DataMatrixDataMode.Auto". The library will automatically select the optimal mode for Unicode encoding.
- Save the JRXML template to apply the settings.
More Data Formats to Encode in Data Matrix
Data Matrix in JasperReport reports supports additional advanced data formats, which are commonly used in business and industrial scenarios. Below are key formats with brief configuration guidelines (detailed steps can be expanded as needed):
- Binary data: Encode binary data (e.g., file byte arrays, encrypted data) by setting "DataMode" to "DataMatrixDataMode.Base256" and using the "ProcessTilde" property to format byte values as "~ddd". Bind the binary data to a Field ($F{}) with a BLOB type from a JDBC DataSource.
- GS1 data elements: Encode GS1 business messages by setting the "FNC1" property to "FNC1.FNC1_1ST_POS" and formatting the data with Application Identifier (AI) codes in parentheses (e.g., "(01)12345678901234").
- Structured Append mode: Split large data across multiple Data Matrix symbols by enabling the "StructuredAppend" property. This is useful for encoding data that exceeds the maximum length of a single Data Matrix.
Data Matrix Barcode Dimension Size in JasperReport Reports
You can fully customize the dimension size of Data Matrix in JasperReport reports, including square and rectangular formats, module size, and Quiet Zones.
Quick to Create Data Matrix with Specified Width
Data Matrix is typically square, so setting the width will automatically adjust the height to maintain a 1:1 aspect ratio. Follow these steps to set a specific width.
Note: Avoid setting the width too large, as it may overlap with other Report Elements (e.g., Static Text (Fixed label text), Text Field (Dynamic field displaying data/variables)).
- Open the Report Item Property panel of the Data Matrix.
- Locate the "BarcodeWidth" property and enter the desired width (e.g., 900 pixels). The height will automatically match the width to maintain a square shape.
- Save the JRXML template to apply the setting.
Note: Avoid setting the width too large, as it may overlap with other Report Elements (e.g., Static Text (Fixed label text), Text Field (Dynamic field displaying data/variables)).
Generate Rectangular Data Matrix with Specified Width and Height
Data Matrix (ECC200) supports 6 rectangular symbols with specific row and column configurations. To create a rectangular Data Matrix, you'll need to set the "FormatMode" property and match the width-height ratio to the row-column ratio of the selected format.
List of the size rectangular format:
Note: If the data exceeds the maximum capacity of the selected rectangular format, the JasperReports Library will automatically select a larger format to accommodate the data.
List of the size rectangular format:
- 8 rows x 18 columns
- 8 rows x 32 columns
- 12 rows x 26 columns
- 12 rows x 36 columns
- 16 rows x 36 columns
- 16 rows x 48 columns
- Open the Report Item Property panel.
- Set the "FormatMode" property to the desired rectangular format (e.g., "DataMatrixFormatMode.Format_16X48" for 16 rows x 48 columns).
- Set the "BarcodeWidth" and "BarcodeHeight" properties to match the row-column ratio of the selected format. For example, 16 rows x 48 columns has a 1:3 ratio, so set "BarcodeWidth" to 900 and "BarcodeHeight" to 300.
- Enter the data to encode in the "Data" field (static or dynamic via Expression).
- Save the JRXML template to apply the settings.
Note: If the data exceeds the maximum capacity of the selected rectangular format, the JasperReports Library will automatically select a larger format to accommodate the data.
Advanced Data Matrix Dimension Settings
You can fine-tune the Data Matrix dimensions using advanced properties in the Report Item Property panel, including module size, unit of measure, and Quiet Zones. The width of a Data Matrix (including Quiet Zones) can be calculated using the formula: W = Row * X + 2Q, where:
W = Barcode widthRow = Modules per row (determined by FormatMode)X = Width of each moduleQ = Width of the Quiet Zone (margin)
Configure the following advanced settings:
W = Barcode widthRow = Modules per row (determined by FormatMode)X = Width of each moduleQ = Width of the Quiet Zone (margin)
Configure the following advanced settings:
- UOM (Unit of Measure): Select the unit (PIXEL, CM, or INCH) for dimension settings. Default is PIXEL.
- X: Set the width of each module (minimum width is defined by your application's specifications).
- FormatMode: Select the Data Matrix symbol size (square or rectangular) as needed.
- Quiet Zones: Set the LeftMargin, RightMargin, TopMargin, and BottomMargin properties (minimum width is equal to the module width X). These properties control the empty space around the Data Matrix.
- AutoResize: Set to "false" to manually control dimensions; set to "true" to let the library adjust size based on data.
Data Matrix Color and Image Option Settings in JasperReport Reports
You can customize the colors and image formats of Data Matrix in JasperReport reports to match your report's design. All settings are configured in the Report Item Property panel, and we'll cover both raster and vector image formats.
Colors in Data Matrix
By default, Data Matrix uses a dark (black) foreground (bars) and light (white) background (spaces), but you can customize these colors to align with your report's style. Ensure high contrast between foreground and background to maintain readability.
Configure the color properties:
Configure the color properties:
- ForeColor: Set the color of the Data Matrix's bars (default: Black). You can select a predefined color or enter a custom RGB value (e.g., #FF0000 for Red).
- BackColor: Set the color of the Data Matrix's spaces (default: White).
- Standard dark-on-light: ForeColor = Black, BackColor = White (default).
- Light-on-dark: ForeColor = White, BackColor = Black.
- Custom color: ForeColor = Red, BackColor = White (ensure high contrast).
Image Settings in Data Matrix
Data Matrix in JasperReport reports can be exported as raster images (e.g., PNG, JPEG, BITMAP) or vector images (e.g., SVG, EPS). Vector images are ideal for high-quality printing, while raster images are suitable for digital display.
Configure raster image settings:
Configure raster image settings:
- ImageFormat: Select the desired raster format (e.g., PNG, JPEG) from the dropdown.
- Resolution: Set the image resolution (e.g., 300 DPI) for high-quality printing.
Create Data Matrix with Advanced Options in JasperReport Reports
JasperReport reports support advanced Data Matrix settings to meet specific business needs, including Format Mode, Structured Append mode, and FNC1 mode.
Data Matrix Format Mode
The Data Matrix ISO standard specifies 24 square symbols and 6 rectangular symbols for ECC 200. Each symbol size has a specific number of rows and columns, which determines its data capacity. You can manually select the Format Mode in the Report Item Property panel to control the Data Matrix size.
Note: If the data exceeds the maximum capacity of the selected FormatMode, the JasperReports Library will automatically select a larger format to ensure all data is encoded.
- Select the Data Matrix and open the Report Item Property panel.
- Locate the "FormatMode" property and select the desired symbol size (e.g., "DataMatrixFormatMode.Format_48X48" for a 48x48 square Data Matrix).
- Enter the data to encode in the "Data" field.
- Save the JRXML template to apply the setting.
Note: If the data exceeds the maximum capacity of the selected FormatMode, the JasperReports Library will automatically select a larger format to ensure all data is encoded.
Data Matrix Structured Append Mode
Structured Append mode allows you to split large data into blocks and store it across multiple Data Matrix symbols (up to 16). This is useful for encoding data that exceeds the maximum length of a single Data Matrix.
- Select the Data Matrix and open the Report Item Property panel.
- Set the "StructuredAppend" property to "true" to enable the mode.
- Configure the following properties:
- SymbolCount: The total number of Data Matrix symbols needed to store the entire data message (e.g., 3 for splitting data into 3 symbols).
- SymbolIndex: The position of the current Data Matrix in the sequence (starts at 0 for the first symbol).
- FileId: A unique integer (e.g., 999) that identifies all symbols belonging to the same data message. All symbols must have the same FileId.
- Enter the portion of the data to encode in the current Data Matrix (e.g., the first 100 characters for SymbolIndex 0).
- Repeat the process for each symbol (adjust SymbolIndex for each Data Matrix).
- Save the JRXML template for each symbol (or use a Subreport (Embedded nested report) to generate multiple symbols in a single report).
Data Matrix FNC1 in the First Position
When FNC1 appears in the first position of a Data Matrix, it signals that the encoded data conforms to the GS1 Application Identifier (AI) standard. This is commonly used in supply chain and retail reports to encode product information (e.g., GTIN, batch number).
Note: Ensure the AI codes and data lengths comply with the GS1 standard. Incorrect formatting will prevent the scanner from recognizing the GS1 data.
- Select the Data Matrix and open the Report Item Property panel.
- Locate the "FNC1" property and set it to "FNC1.FNC1_1ST_POS".
- Enter the GS1 data in the "Data" field, with AI codes surrounded by parentheses (e.g., "(01)12345678901234(10)ABC123").
- Set the "DataMode" to "DataMatrixDataMode.Auto" to ensure correct encoding.
- Save the JRXML template to apply the setting.
Note: Ensure the AI codes and data lengths comply with the GS1 standard. Incorrect formatting will prevent the scanner from recognizing the GS1 data.
iReport Barcode Data Matrix Generator - Property Settings
| Category | Properties | Value | Comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic | Property: Data | Type: expression
Default: ""
|
Barcode value to encode
Data Matrix Valid Data Char Set:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data Matrix Special |
Property: processTilde
URL: PROCESS-TILDE |
Type: bool
Default: true |
Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default value is true.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Data Matrix Data Mode |
Type: int
Default: AUTO |
Data Matrix data encoding mode.
Valid values are:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Data Matrix Format Mode |
Type: int
Default: 10X10 |
Specifies the Data Matrix Format to use on that symbology. Valid values see options in the list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Data Matrix FNC1 Mode |
Type: int
Default: NONE |
To encode GS1 compatible Data Matrix barcode, you need set fnc1Mode value to "ENABLE". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: 2D Barcode Structured Append |
Type: boolean
Default: false |
Set Structured Append property to true, then Structured Append is enabled. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: 2D Barcode Symbol Count |
Type: int
Default: 0 |
Set Symbol Count property to the number of total symbols which make the sequence. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: 2D Barcode Symbol Index |
Type: int
Default: 0 |
Set Symbol Index property to the position of current symbol in the secuence (Start with 0). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: 2D Barcode File Id |
Type: int
Default: 0 |
Set File Id property to be identified to the same file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Barcode Size Related |
Property: Unit of Measure |
Type: int
Default: 0 (pixel) |
Unit of meature for all size related settings in the library.
Valid values: 0: pixel; 1: inch; 2: cm. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: X |
Type: float
Default: 1 |
Width of barcode bar module (narrow bar), default is 1 pixel | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Left Margin | Type: float
Default: 0 |
Barcode image left margin size. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Right Margin | Type: float
Default: 0 |
Barcode image right margin size. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Top Margin | Type: float
Default: 0 |
Barcode image top margin size. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Bottom | Type: float
Default: 0 |
Barcode image bottom margin size. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Resolution (in dpi) | Type: int
Default: 72 |
Barcode image resolution in DPI (Dots per inch). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Rotate |
Type: int
Default: 0 (rotate angle in 0 degree) |
Valid values:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary
This guide has provided a comprehensive, step-by-step approach to generating and customizing Data Matrix (a type of 2d Barcode) in JasperReport reports using Jaspersoft Studio or iReport Designer. We covered all key aspects, including basic generation, data encoding (standard and advanced), dimension customization, color and image settings, and advanced modes like Structured Append and FNC1.
