Java Barcode is a Jasper Reports barcode generator which generates high quality 1D (linear) and 2D (matrix) barcodes in Jasper Reports projects.
Libraries Needed
-
barcode.jar (Download free evaluation of Java Barcode)
- jasperreports-2.0.2.jar or later version (Download JasperReports)
How to generate barcodes in Jasper Reports using Java Barcode?
-
Draw barcodes on your Jasper report.
<image> <reportElement x="265" y="44" width="100" height="50"/> <imageExpression class="net.sf.jasperreports.engine.JRRenderable"> <![CDATA[new com.onbarcode.barcode.jasper.JasperRenderer( com.onbarcode.barcode.jasper.BarcodeGenerator.draw(2, "12345", "", "X=2&Y=60"))]]> </imageExpression> </image>
BarcodeGenerator.draw method accepts 4 parameters:
the first is the barcode type in int,
the second is the barcode data to encode, in String,
the third is the supplement barcode data in String,
the last is the barcode settings String. More details about barcode settings string, please check each barcode type property settings
How to generate barcodes using data from data source?
- 1. Define the data field in your jasper report
-
2. Draw barcodes on your Jasper report.
<image> <reportElement x="265" y="44" width="100" height="50"/> <imageExpression class="net.sf.jasperreports.engine.JRRenderable"> <![CDATA[new com.onbarcode.barcode.jasper.JasperRenderer( com.onbarcode.barcode.jasper.BarcodeGenerator.draw(2, $F{data field} + "", "", "X=2&Y=60"))]]> </imageExpression> </image>
