How to generate UPC-A barcodes in JasperReport?
Please follow the steps to create a UPC-A barcode in iReport. View details here: how to generate and print barcodes in iReport reprts.
One more method to print UPC-A: stream UPC-A barcodes in iReport using Java Barcode Generator buildin Servlet web application.
One more method to print UPC-A: stream UPC-A 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
- Right click on the image and edit its "Properties", and set property "Expression Class" to "net.sf.jasperreports.engine.JRRenderable";
- To input UPC-A barcode data manually, set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(19, "12345678901", "", "X=2&Y=60"))" - To print UPC-A with data from database, please set property "Image Expression" to "new com.onbarcode.barcode.jasper.JasperRenderer(
com.onbarcode.barcode.jasper.BarcodeGenerator.draw(19, $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 UPC-A property table below
UPC-A barcode with 2-digit addon
UPC-A barcode with 5-digit addon
Print and Customize UPC-A Barcodes in JasperReport Reports
You can fully customize UPC-A barcodes in JasperReport reports to meet your report design and scanning requirements. These settings include quiet zone indicators, digit spacing, digit position, and font size adjustments.
The key customization properties for UPC-A barcodes in JasperReport reports are:
The key customization properties for UPC-A barcodes in JasperReport reports are:
- ShowQuietZoneIndicator: Controls whether to display or hide the UPC barcode quiet zone indicator. The default value is true.
- UPCEANLeadDigitSpace: Defines the space between the first digit (Human Readable Interpretation, HRI) and the start character bar. The default value is 0.
- UPCEANTrailDigitSpace: Defines the space between the stop character bar and the quiet zone indicator. The default value is 0.
- UPCEANLeadTrailDigitSizeRatio: Controls the font size of the first and last digits relative to the rest of the digits in the HRI. The default value is 1.0f (equal size).
Customize UPC-A Quiet Zone Indicator
The quiet zone indicator is a small mark at the end of the UPC-A barcode, indicating the end of the quiet zone (empty space around the barcode). You can show or hide this indicator via the Report Item Property panel, following these steps:
Note: Do not reduce the RightMargin below the minimum 9X requirement when hiding the quiet zone indicator. Insufficient quiet zone will cause scanning errors.
- Select the UPC-A Barcode Component and open the Report Item Property panel.
- Locate the "ShowQuietZoneIndicator" property.
- Set it to "false" to hide the quiet zone indicator; leave it as "true" (default) to display it.
- Save the JRXML template to apply the setting.
Note: Do not reduce the RightMargin below the minimum 9X requirement when hiding the quiet zone indicator. Insufficient quiet zone will cause scanning errors.
Customize UPC-A First/Last Digit Spacing, Position, and Font Size
You can adjust the spacing between the first/last digits and the barcode bars, the vertical position of the first/last digits, and their font size relative to other digits.
Note: Avoid setting the UPCEANLeadTrailDigitSizeRatio too small (e.g., below 0.5f), as this may make the first/last digits unreadable. Also, ensure the vertical shift does not move the digits outside the report's Report Band.
- UPCEANLeadDigitSpace: Adjusts the space between the first digit and the start bar.
- UPCEANTrailDigitSpace: Adjusts the space between the stop bar and the quiet zone indicator.
- UPCEANLeadDigitYShift: Adjusts the vertical offset (up/down) of the first digit in the HRI.
- UPCEANTrailDigitYShift: Adjusts the vertical offset (up/down) of the last digit in the HRI.
- UPCEANLeadTrailDigitSizeRatio: Adjusts the font size of the first and last digits relative to the rest (e.g., 0.6f means 60% of the default font size).
Note: Avoid setting the UPCEANLeadTrailDigitSizeRatio too small (e.g., below 0.5f), as this may make the first/last digits unreadable. Also, ensure the vertical shift does not move the digits outside the report's Report Band.
Calculate UPC-A Check Digit in JasperReport Reports
The UPC-A check digit is a mandatory component calculated using a modulo 10 (mod 10) algorithm. It ensures data integrity by validating the UPC-A number. The JasperReport Barcode Generator Library automatically calculates and adds the check digit if you provide 11 digits, but understanding the calculation process helps in troubleshooting invalid data.
JasperReport Barcode UPC-A Generator - Property Settings
| Category | Properties | Value | Comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic | Property: Data | Type: expression
Default: ""
|
Barcode value to encode.
UPC-A 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). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UPC-A 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 | 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
Here we have learned how to print and customize UPC-A barcodes in JasperReport reports using Jaspersoft Studio or iReport Designer. We covered all key aspects, including basic UPC-A generation, customization of quiet zone indicators and digit properties, and check digit calculation.
