How to generate PDF-417 barcodes in iReport?
This is a sample to create PDF-417 barcode in iReport. More dtails, view here: how to generate and print barcodes in iReport reprts.
One more guide for you to stream PDF-417 barcodes in iReport using Java Barcode Generator buildin Servlet web application.
One more guide for you to stream PDF-417 barcodes in iReport using Java Barcode Generator buildin Servlet web application.
- Create a new report in iReport, and add barcode.jar to report classpath from the downloaded trial package
- 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 PDF-417 barcode data manually, set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(101, "12345", "", "X=2&Y=60"))" - To print PDF-417 with data from database, please set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(101, $F{data field} + "", "", "X=2&Y=60"))";
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 PDF-417 property table below
PDF-417 Barcode Data Characters Encoding in JasperReport Reports
To generate a valid, scannable PDF-417 in JasperReport reports, it's critical to understand its encoding rules. Including valid character sets, data encoding modes, and maximum data length.
PDF-417 Valid Character Set
PDF-417 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 (128 characters): This includes 95 printable characters and 33 control characters (non-printable). It covers standard letters, numbers, symbols, and control codes.
- Extended ASCII: Values 128-255 in accordance with ISO 8859-1. This supports additional characters such as accented letters, common in non-English languages.
- Up to 811,800 different character sets or data interpretations: This flexibility allows PDF-417 to adapt to various international and industry-specific requirements.
- Various function codewords for control purposes: These codewords manage encoding behavior and data structure, ensuring compatibility with different scanning systems.
PDF-417 Data Encoding Mode
PDF-417 supports three compact encoding modes to optimize data storage. 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 DataMode in Jaspersoft Studio or iReport Designer:
In the Report Item Property panel, set "DataMode" to "PDF417DataMode.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 PDF-417 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:
- Text Compaction mode: Permits all printable ASCII characters (values 32-126 per ISO/IEC 646 (IRV)) and selected control characters. Ideal for standard text data.
- Byte Compaction mode: Permits all 256 possible 8-bit byte values. This includes all ASCII characters (0-127) and supports international character sets via Extended ASCII or ECI mode.
- Numeric Compaction mode: Permits efficient encoding of numeric data strings. This mode offers the highest storage efficiency for numbers (e.g., serial numbers, inventory codes).
- PDF417DataMode.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.
- Save the JRXML template to apply the DataMode setting.
In the Report Item Property panel, set "DataMode" to "PDF417DataMode.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.
PDF-417 Maximum Data Length
The maximum data length a PDF-417 can encode depends on its encoding Data Mode and Error Correction Level (ECL). The values below apply to ECL 0 (the lowest error correction level). Higher ECLs will reduce the maximum data length slightly.
- Text Compaction mode: 1,850 characters. Suitable for standard text and control characters.
- Byte Compaction mode: 1,108 characters. Ideal for Extended ASCII, binary data, or international character sets.
- Numeric Compaction mode: 2,710 characters. The most efficient mode for large sets of numeric data.
How to Encode Text in PDF-417 Using Jaspersoft Studio/iReport
In practical report design, you may need to encode various text types into PDF-417, including ASCII text, non-printable characters, Unicode text, binary data, GS1 messages, and ECI mode data.
Generate PDF-417 with ASCII Text Encode
PDF-417 supports all 128 ASCII characters, including 95 printable characters and 33 non-printable control characters. Encoding printable ASCII text is straightforward, while non-printable characters require a specific format.
Note: Common errors here include forgetting to set "ProcessTilde" to "true" or using the wrong DataMode (e.g., Text instead of Byte). Both will prevent non-printable characters from encoding correctly.
- Non-printable control characters (e.g., [CR], [LF]) cannot be directly entered into the "Data" field. You must convert them to a specific format.
- Convert the non-printable character to a string in the format "~ddd", where "ddd" is the three-digit ASCII value of the character. For example, [CR] has an ASCII value of 13, so it becomes "~013".
- In the Report Item Property panel, set the "ProcessTilde" property to "true". This tells the JasperReports Library to interpret the "~ddd" format as a non-printable character.
- Set the "DataMode" to "PDF417DataMode.Byte" (required for non-printable characters).
- Enter the formatted string into the "Data" field (e.g., "a~013bc" to encode [CR] between "a" and "b").
- Save the JRXML template to apply the settings.
Note: Common errors here include forgetting to set "ProcessTilde" to "true" or using the wrong DataMode (e.g., Text instead of Byte). Both will prevent non-printable characters from encoding correctly.
Generate PDF-417 with Unicode Text Encode
You can easily encode Unicode text (e.g., Arabic, Chinese, Cyrillic) into PDF-417 in JasperReport reports using the Report Item Property panel. This is useful for international reports that require non-ASCII text encoding.
Note: If the decoded text is garbled, check that "EncodeUnicodeText" is set to "true" and the DataMode is "Auto". Also, ensure the scanner supports the specific Unicode character set (e.g., Arabic, Cyrillic).
- Select the PDF-417 and open the Report Item Property panel.
- Locate the "EncodeUnicodeText" property and set it to "true". This 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 "PDF417DataMode.Auto". The library will automatically select the optimal mode for Unicode encoding.
- Save the JRXML template to apply the settings.
Note: If the decoded text is garbled, check that "EncodeUnicodeText" is set to "true" and the DataMode is "Auto". Also, ensure the scanner supports the specific Unicode character set (e.g., Arabic, Cyrillic).
Other Data Formats in PDF-417
PDF-417 in JasperReport reports supports additional advanced data formats, commonly used in business and industrial scenarios.
- Binary data: Encode binary data (e.g., file byte arrays, encrypted data) by setting "DataMode" to "PDF417DataMode.Byte" 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.
- ECI mode data: To encode data using the Extended Channel Interpretation (ECI) protocol (for international character sets), enable ECI mode in the Report Item Property panel and select the appropriate ECI code for your character set. This is useful for encoding non-ISO 8859-1 characters.
PDF-417 2D Barcode Dimension Width and Height Settings in JasperReport Reports
You can fully customize the dimension size of PDF-417 in JasperReport reports, including module size, row/column count, margins, and unit of measure.
The following settings are available in the Report Item Property panel to customize PDF-417 dimensions.
The following settings are available in the Report Item Property panel to customize PDF-417 dimensions.
- UOM (Unit of Measure): Select the unit for dimension settings: PIXEL, CM, or INCH. Default is PIXEL.
- X: Width of the bar module (the smallest unit of the barcode). The minimum width is defined by your application's specifications (typically 2-5 pixels).
- XtoYRatio: The ratio of bar width (X) to bar height. Default value is 0.3333333f (1:3 width-to-height ratio).
- RowCount: Number of rows in the PDF-417 symbol. Valid range is 3 to 90.
- ColumnCount: Number of data columns per row. Valid range is 1 to 30.
- LeftMargin, RightMargin, TopMargin, BottomMargin: Quiet zone (empty space) around the PDF-417. The minimum width of each margin is 2X (twice the module width X).
- Resolution: Image resolution (e.g., 300 DPI) for high-quality printing.
Create, Print PDF-417 Barcode with Options Using Jaspersoft Studio/iReport
JasperReport reports support advanced PDF-417 options to meet specific business needs, including Error Correction Level (ECL), Compact (Truncated) PDF-417, and Macro PDF-417.
PDF-417 Error Detection and Correction (ECL) in JasperReport Reports
Each PDF-417 symbol contains error correction codewords to detect and correct scanning errors. The Error Correction Level (ECL) is selectable in the Report Item Property panel, with higher levels providing more error correction but reducing maximum data length.
The ECL property in the Report Item Property panel controls the number of error correction codewords.
Note: Choose an ECL based on your use case. For example, use ECL 0 for indoor, low-risk environments; use ECL 4+ for outdoor or high-damage environments (e.g., product labels exposed to weather).
The ECL property in the Report Item Property panel controls the number of error correction codewords.
- ECL 0: 2 error correction codewords (lowest level, maximum data length)
- ECL 1: 4 error correction codewords
- ECL 2: 8 error correction codewords
- ECL 3: 16 error correction codewords
- ECL 4: 32 error correction codewords
- ECL 5: 64 error correction codewords
- ECL 6: 128 error correction codewords
- ECL 7: 256 error correction codewords
- ECL 8: 512 error correction codewords (highest level, minimum data length)
Note: Choose an ECL based on your use case. For example, use ECL 0 for indoor, low-risk environments; use ECL 4+ for outdoor or high-damage environments (e.g., product labels exposed to weather).
How to Create Compact (Truncated) PDF-417 Barcodes
Compact PDF-417 (also called Truncated PDF-417) is a condensed version of PDF-417, designed for space-constrained reports. It removes the right-row indicator and stop pattern, reducing overall size. It is ideal for scenarios where space is a primary concern and symbol damage is unlikely.
Locate the "Truncated" property and set it to "true" to enable Compact PDF-417.
Note: Compact PDF-417 is more susceptible to damage. Avoid using it in high-damage environments. Use standard PDF-417 with a higher ECL instead.
Locate the "Truncated" property and set it to "true" to enable Compact PDF-417.
Note: Compact PDF-417 is more susceptible to damage. Avoid using it in high-damage environments. Use standard PDF-417 with a higher ECL instead.
Create Macro PDF-417 Barcodes
Macro PDF-417 provides a mechanism to split large data into blocks and store it across multiple PDF-417 symbols. This is similar to the Structured Append feature in QR Code and Data Matrix symbologies and is useful for encoding data that exceeds the maximum length of a single PDF-417.
Up to 99,999 individual PDF-417 symbols can be used to encode data in Macro PDF-417. Each symbol contains control information to ensure the original data is reconstructed correctly, regardless of scanning order.
Note: Ensure all symbols have the same MacroFileId and correct MacroSymbolIndex. Incorrect settings will prevent the scanner from reconstructing the original data.
Up to 99,999 individual PDF-417 symbols can be used to encode data in Macro PDF-417. Each symbol contains control information to ensure the original data is reconstructed correctly, regardless of scanning order.
- Select the first PDF-417 in your JRXML template (for the first data block).
- Open the Report Item Property panel and set the "MacroPDF417" property to "true" to enable Macro mode.
- Configure the following control properties:
- MacroSymbolCount: The total number of PDF-417 symbols needed to store the entire data message (e.g., 3 for splitting data into 3 blocks).
- MacroSymbolIndex: The position of the current PDF-417 in the sequence (starts at 0 for the first symbol).
- MacroFileId: A unique identifier (integer) for all symbols in the same Macro PDF-417 set. All symbols must have the same MacroFileId.
- Enter the portion of the data to encode in the current PDF-417 (e.g., the first 1,000 characters for MacroSymbolIndex 0).
- Repeat the process for each additional symbol (add new Barcode Components to the report, adjust MacroSymbolIndex for each, and keep MacroFileId consistent).
- Save the JRXML template to apply the settings. You can use a Subreport (Embedded nested report) to organize multiple Macro PDF-417 symbols in a single report.
Note: Ensure all symbols have the same MacroFileId and correct MacroSymbolIndex. Incorrect settings will prevent the scanner from reconstructing the original data.
iReport Barcode PDF-417 Generator - Property Settings
| Category | Properties | Value | Comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic | Property: Data | Type: expression
Default: ""
|
Barcode value to encode
PDF-417 Valid Data Char Set:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PDF 417 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: PDF 417 Data Mode | Type: int
Default: AUTO |
Valid values:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: PDF 417 Error Correction Level | Type: int
Default: 2 |
Error correction level, values are from 0 to 8. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: PDF 417 Row Count | Type: int
Default: 3 |
The number of rows for PDF417. The value range is from 3 to 90. The default is 3. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: PDF 417 Column Count | Type: int
Default: 5 |
Number of columns. The value range is from 1 to 30. The default is 5. Increase this value, if your data size is large. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: PDF 417 Truncated | Type: boolean
Default: false |
truncated PDF417 may be used where space considerations are a primary concern and symbol damage is unlikely. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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: Y | Type: float
Default: 30 |
Height of barcode bar module, default is 30 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:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Font Style |
Property: Show Text |
Type: boolean
Default: true |
If true, display barcode data text under the barcode, otherwise do not display. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Text Font Size |
Type: int
Default: 11 |
Barcode text font size. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Text Margin |
Type: float
Default: 6 |
Space between barcode and barcode data text, default is 6 pixels | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary
This guide has provided a comprehensive, step-by-step approach to generating and customizing PDF-417 in JasperReport reports using Jaspersoft Studio or iReport Designer. We covered all key aspects, including basic generation, data encoding (standard and advanced), dimension customization, and advanced options like Error Correction Level, Compact PDF-417, and Macro PDF-417.
