How to print EAN-13 barcodes in JasperReport?
Here are simple steps to create a EAN-13 barcode in iReport. View details here: How to create and print barcodes in iReport reprts.
One more guide for you to How to stream EAN-13 barcodes in iReport using Java Barcode Generator buildin Servlet web application.
One more guide for you to How to stream EAN-13 barcodes in iReport using Java Barcode Generator buildin 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
- Select the image and edit its "Properties", and set property "Expression Class" to "net.sf.jasperreports.engine.JRRenderable"
- To input EAN-13 barcode data manually, set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(18, "123456789012", "", "X=2&Y=60"))" - To print EAN-13 with data from database, please set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(18, $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 EAN-13 property table below
EAN-13 Barcode Add-on Symbol
EAN-13 barcodes can include a 2-digit or 5-digit add-on symbol, which is positioned after the right Margin (External spacing around an element) (quiet zone) of the main EAN-13 symbol. This add-on provides additional data (e.g., weight, price) and is fully configurable in Jaspersoft Studio or iReport Designer via the Report Item Property pane.
- Select the EAN-13 Barcode Component and open the Report Item Property panel.
- Set the "Barcode Type" to match the add-on length:
Select "EAN13_2" for a 2-digit add-on.
Select "EAN13_5" for a 5-digit add-on. - Enter the main EAN-13 data (12 or 13 digits) in the "Data" field (static text or dynamic Expression).
- Locate the "SupData" (supplementary data) property in the Report Item Property panel and enter the add-on data (2 or 5 digits, matching the selected barcode type).
- Save the JRXML template to apply the settings.
EAN-13 Barcode Text (Human Readable Interpretation, HRI)
The GS1 System recommends using the OCR-B font for the Human Readable Interpretation (HRI). The text displayed below the EAN-13 barcode.
You can customize the HRI's font and the spacing between the barcode bars and the text via the Report Item Property panel.
- Select the EAN-13 Barcode Component and open the Report Item Property panel.
- Locate the "TextFont" property and select the OCR-B font (or your preferred font). Configure the font size (e.g., 12pt) and style (e.g., Regular) as needed.
- Locate the "TextMargin" property and enter the desired spacing (e.g., 10 pixels, or 1X based on your X value). This controls the space between the barcode bars and the HRI text.
- Ensure the "Data" field contains valid EAN-13 data (12 or 13 digits) and the "Barcode Type" is set to "EAN13" (or EAN13_2/EAN13_5 if using an add-on).
- Save the JRXML template to apply the settings.
Customize EAN-13 Barcode in JasperReport Reports
You can further customize EAN-13 barcodes in JasperReport reports using additional properties in the Report Item Property panel. These settings allow you to adjust quiet zone indicators and spacing between digits and barcode bars, enhancing the barcode's appearance and readability.
EAN Barcode Quiet Zone Indicator
The quiet zone indicator is a small mark at the end of the EAN-13 barcode, indicating the end of the quiet zone. You can show or hide this indicator via the Report Item Property panel:
Note: Hiding the quiet zone indicator may affect scannability. Only do so if required by your report design, and ensure the quiet zone (LeftMargin, RightMargin) is still sufficient (minimum 10X).
- Select the EAN-13 Barcode Component and open the Report Item Property panel.
- Locate the "ShowQuietZoneIndicator" property.
- Set it to "true" (default) to display the quiet zone indicator, or "false" to hide it.
- Save the JRXML template to apply the setting.
Note: Hiding the quiet zone indicator may affect scannability. Only do so if required by your report design, and ensure the quiet zone (LeftMargin, RightMargin) is still sufficient (minimum 10X).
EAN-13 First and Last Digit Space
You can adjust the spacing between the first digit and the start bar, and between the stop bar and the quiet zone indicator, using two properties in the Report Item Property panel:
Note: Avoid excessive spacing, as it may increase the barcode's overall width and cause layout issues in your report. Test the spacing in Preview Mode before finalizing.
- UPCEANLeadDigitSpace: Controls the space between the first digit (HRI) and the start character bar. Default value is 0.
- UPCEANTrailDigitSpace: Controls the space between the stop character bar and the quiet zone indicator. Default value is 0.
Note: Avoid excessive spacing, as it may increase the barcode's overall width and cause layout issues in your report. Test the spacing in Preview Mode before finalizing.
Verify and Calculate EAN-13 Check Digit
The EAN-13 check digit is a mandatory component calculated using a modulo 10 (mod 10) algorithm. It ensures data integrity and is automatically handled by the JasperReport Barcode Library. You do not need to calculate it manually, but understanding the process helps in troubleshooting invalid data.
How the JasperReports Library Handles Check Digits
How the JasperReports Library Handles Check Digits
- If you enter 12 digits in the "Data" field, the JasperReport Barcode Library will automatically calculate and append the 13th check digit.
- If you enter 13 digits, the library will validate the check digit to ensure it is correct. If invalid, it will throw an exception or generate an empty image with "Invalid Barcode Settings".
JasperReport Barcode EAN-13 Generator - Property SettingsTop
| Category | Properties | Value | Comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic | Property: Data | Type: expression
Default: ""
|
Barcode value to encode.
EAN 13 Valid Data Char Set:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: Add CheckSum Char |
Type: boolean
Default: false |
Add CheckSum Char property is not applied here. iReport Barcode will always add a check character in the last digit (modulo 10). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EAN-13 Related | Property: UPC/EAN Supplement Data | Type: expression
Default: ""
|
Set the supplement data to encode. Valid values are 2 or 5 digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: UPC/EAN Supplement Bar Height |
Type: float
Default: 0.8f |
This is a multiplicator of the height of the bar module; The default is 0.8 (80% of Y - bar module height). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property: UPC/EAN Space between main bar and supplement bar |
Type: float
Default: 15 |
The separation between the barcode and the supplement. Default is 15 pixel. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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/b> | 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 EAN-13 barcodes in JasperReport reports using Jaspersoft Studio or iReport Designer. We covered all key aspects, including basic EAN-13 generation, error handling for incorrect data lengths, add-on symbol configuration, HRI customization (font and spacing), advanced barcode settings, and check digit calculation and verification.
