How to generate QR Code barcodes in iReport?
Below is a sample to create QR Code barcodes in iReport. View details here: how to generate and print barcodes in iReport reprts.
One more guide for you to stream QR Code barcodes in iReport using Java Servlet web application.
One more guide for you to stream QR Code barcodes in iReport using Java Servlet web application.
- Create a new report, 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 QR Code barcode data manually, set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(102, "12345", "", "X=2"))" - To print QR Code with data from database, please set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(102, $F{data field} + "", "", "X=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 QR Code property table below
Key QR Code Concepts in JasperReport Design
To effectively generate and customize QR Codes in JasperReport reports, familiarize yourself with the following core concepts, all configured via the Report Item Property panel.
QR Code Encodable Character Set
QR Code (Barcode Component) in JasperReports supports the following data formats, which can be configured based on your needs:
- Numbers (digits 0-9)
- ASCII characters (plain text) – refer to the standard ASCII table for supported characters.
- Unicode text (for international languages like Arabic, Greek, Thai).
- Byte data (default: ISO/IEC 8859-1; configurable to other character sets).
- Kanji characters (compacted into 13 bits for efficient encoding).
QR Code Data Mode
Data Mode determines how the QR Code encodes input data efficiently. In Jaspersoft Studio and iReport Designer, you can select the Data Mode from the Report Item Property panel. There are five available options:
- Auto: The JasperReports Library automatically selects the optimal Data Mode based on the input data (recommended for most use cases).
- Numeric: For encoding only numbers (digits 0-9).
- AlphaNumeric: For alphanumeric data (digits 0-9, uppercase letters A-Z, and nine special characters: space, $ % * + - . / :).
- Byte: For byte data (default: ISO/IEC 8859-1; can be customized via ECI mode).
- Kanji: For encoding Kanji characters (defined in JIS X 0208).
Note: Always set Data Mode to "Auto" if you are unsure about the input data type. It prevents encoding errors.
Maximum Data Length per QR Code
The maximum number of characters a QR Code can encode depends on its Version and Error Correction Level. For Version 40-L (the largest standard QR Code size), the maximum data lengths are:
- Numeric data: 7,089 characters
- Alphanumeric data: 4,296 characters
- Byte data: 2,953 characters
- Kanji data: 1,817 characters
Note: If your data exceeds the maximum length for a single QR Code, use the QR Code Structured Append mode (covered later).
Encode Different Text Formats into QR Code
Below are step-by-step guides to encode various text formats into QR Codes in Jaspersoft Studio/iReport, with all settings configured in the Report Item Property panel.
Encode ASCII Non-Printing Characters
ASCII non-printing characters (e.g., Carriage Return [CR]) require special configuration to encode into QR Codes. Follow these steps:
- Open the Report Item Property panel for the Barcode Component (QR Code type).
- Set the "ProcessTilde" property to "true" (enables the use of "~" to represent special characters).
- Set "DataMode" to "Auto" (the tool will automatically detect the encoded character).
- In the "Data" field, enter the non-printing character as a three-digit ASCII value prefixed with "~" (e.g., "~013" for [CR]).
- Save the JRXML template.
Note: If the QR Code fails to decode, verify that "ProcessTilde" is set to "true" and the ASCII value is correctly formatted as "~ddd".
Encode Unicode Text (International Languages)
QR Code does not support Unicode text by default. To encode international text (e.g., Thai, Arabic), use one of two methods: convert the text to a UTF-8 byte array and use Byte mode, or use ECI mode. Below is the UTF-8 byte array method:
- Open the Report Item Property panel for the QR Code.
- Set "ProcessTilde" to "true" (enables encoding of byte values).
- Set "DataMode" to "Byte" (required for encoding UTF-8 byte arrays).
- Convert the Unicode text to a UTF-8 byte array and format each byte as "~ddd" (three-digit value prefixed with "~"). For example:
Thai text "สวัสดี" converts to a UTF-8 byte array; each byte is formatted as "~ddd" (e.g., "~224~184~165..." for the full text). - Enter the formatted byte string into the "Data" field of the Report Item Property panel.
- Save the JRXML template.
Encode GS1 QR Code
GS1 QR Code is a specialized format for encoding GS1 data elements (Application Identifier [AI] code + data). Follow these steps to generate it:
- Open the Report Item Property panel for the QR Code.
- Set the "FNC1" property to "FNC1.FNC1_1ST_POS" (enables GS1 encoding).
- Set "DataMode" to "Auto" (the tool will detect the GS1 format).
- Enter the GS1 data (with AI codes in parentheses) into the "Data" field.
- Save the JRXML template.
Note: Ensure the AI codes are properly formatted in parentheses; missing parentheses will cause encoding errors.
Encode Binary Data
Most 2D barcode symbologies (including QR Code) support binary data encoding. To encode binary data in JasperReport reports:
- Open the Report Item Property panel for the QR Code.
- Set "DataMode" to "Byte" (required for binary data).
- Convert the binary data to a formatted string using "~ddd" for each byte (similar to Unicode encoding).
- Enter the formatted string into the "Data" field.
- Save the JRXML template.
Encode Kanji Text
Kanji characters require the "Kanji" Data Mode and special formatting. Follow these steps:
- Open the Report Item Property panel for the QR Code.
- Set "ProcessTilde" to "true" (enables Kanji formatting).
- Set "DataMode" to "Kanji" (critical for correct encoding).
- Convert each Kanji character's SJIS value to a five-digit decimal number, prefixed with "~9" (e.g., "点茗" converts to "~937727~958538").
- Enter the formatted string into the "Data" field.
- Save the JRXML template.
Note: Ensure the SJIS values are within the valid ranges; invalid values will cause encoding failures.
Customize QR Code Dimensions and Appearance
You can customize the QR Code's dimensions, margins (Quiet Zone), and colors via the Report Item Property panel in Jaspersoft Studio/iReport. Below are the key customization options.
QR Code Dimension (Width and Height)
QR Codes are square, so setting the width will automatically adjust the height to match. Follow these steps:
- Open the Report Item Property panel.
- Locate the "BarcodeWidth" property and enter the desired width (e.g., 200 pixels).
- The height will automatically adjust to match the width (maintaining the square aspect ratio).
- Save the JRXML template.
Note: Avoid setting the width too small (less than 100 pixels), as this may make the QR Code unreadable.
Quiet Zone Configuration
The Quiet Zone is the empty space around the QR Code (required for scanners to detect the code). You can set the Quiet Zone using four margin properties in the Report Item Property panel.
- Select the QR Code and open the Report Item Property panel.
- Set the following margin properties to the desired value (e.g., 50 pixels each):
- LeftMargin: Empty space on the left of the QR Code.
- RightMargin: Empty space on the right.
- TopMargin: Empty space at the top.
- BottomMargin: Empty space at the bottom.
- Save the JRXML template.
Note: The recommended Quiet Zone is at least 4 modules (pixels) wide; smaller margins may cause scanning issues.
QR Code Color Customization
You can customize the QR Code's foreground (bar) and background (space) colors via the Report Item Property panel.
- Select the QR Code and open the Report Item Property panel.
- Set the "ForeColor" property to the desired bar color (e.g., Red).
- Set the "BackColor" property to the desired background color (e.g., White).
- Save the JRXML template.
Note: Use high-contrast colors (e.g., black foreground on white background) for best readability; low-contrast colors may make the QR Code unreadable.
Advanced QR Code Feature Settings
Jaspersoft Studio and iReport Designer support advanced QR Code settings, all configured in the Report Item Property panel. These settings enhance the functionality and flexibility of the QR Code.
Error Correction Level (ECL)
QR Code uses Reed-Solomon error correction to recover data if the code is damaged. There are four levels (increasing in error recovery capacity):
- L: 7% error recovery (default)
- M: 15% error recovery
- Q: 25% error recovery
- H: 30% error recovery
- Select the QR Code and open the Report Item Property panel.
- Locate the "ECL" property and select the desired error correction level (e.g., M).
- Save the JRXML template.
Note: Higher error correction levels increase the QR Code size; use H level only if the code will be exposed to potential damage.
QR Code Version
QR Codes have 40 sizes (Versions 1 to 40), with Version 1 being the smallest and Version 40 the largest. The Version determines the maximum data capacity.
- Select the QR Code and open the Report Item Property panel.
- Locate the "Version" property and select the desired version (e.g., V3).
- Save the JRXML template.
Note: If the QR Code encoding data exceeds the capacity of the selected Version, the JasperReports Barcode Library will automatically upgrade to a higher Version.
Structured Append Mode
Structured Append mode allows splitting large data into up to 16 QR Codes (symbols) that can be scanned in sequence to reconstruct the full data.
- Select the QR Code and open the Report Item Property panel.
- Set "StructuredAppend" to "true" (enables the mode).
- Set "SymbolCount" to the total number of symbols (e.g., 3 for three QR Codes).
- Set "SymbolIndex" to the position of the current symbol (0 for the first symbol, 1 for the second, etc.).
- Enter the portion of the data assigned to this symbol in the "Data" field.
- Repeat for each symbol (create a separate QR Code for each index).
- Save the JRXML template.
Note: Ensure all symbols have the same "SymbolCount" and unique "SymbolIndex" values; mismatched values will prevent data reconstruction.
FNC1 in First Position
This mode identifies the QR Code as encoding GS1 data (as covered in Section 3.3). To enable it.
- Select the QR Code and open the Report Item Property panel.
- Set the "FNC1" property to "FNC1.FNC1_1ST_POS".
- Enter the GS1 data in the "Data" field (with AI codes in parentheses).
- Save the JRXML template.
iReport Barcode QR Code Generator - Property Settings
| Category | Properties | Value | Comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic | Property: Data | Type: expression
Default: ""
|
Barcode value to encode
QRCode Valid Data Char Set:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QRCode Special |
Property: Process Tilde | Type: boolean
Default: true |
Set the Process Tilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default is true.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: QRCode Data Mode | Type: int
Default: AUTO |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: QRCode Error Correction Level | Type: int
Default: L |
QRCode Error Correction Level.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: QRCode FNC1 Mode |
Type: int
Default: NONE |
To encode GS1 compatible QR-Code barcode, you need set FNC1 Mode value to "ENABLE". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: QRCode Version | Type: int
Default: 1. |
Valid values are from 1 to 40. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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, structured approach to generating and customizing QR Codes (Barcode Component) in JasperReport reports using Jaspersoft Studio or iReport Designer.
It covers:
- Basic QR Code generation follows a three-phase process (Preparation, Execution, Verification) and requires adding a Barcode Component to a Report Band.
- Data Mode, ProcessTilde, and FNC1 are critical properties for encoding different text formats (ASCII non-printable, Unicode, GS1, Kanji, binary data).
- QR Code dimensions, Quiet Zone, and colors can be customized to meet specific design requirements.
- Advanced settings (ECL, Version, Structured Append, ECI) enhance the functionality and reliability of QR Codes in JasperReport reports.
