Project

General

Profile

How to use barcodes in iReport 3.1.x

How to use barcodes in iReport 3.1.x

If we want to show barcodes in iReport we first need to create a jarfile that contains the class that renders images from barcodes:

  • First download jasperReports on http://www.jasperforge.org and install this. * Download Apache Ant from http://ant.apache.org and install this. Make sure to add the ant\lib folder to your PATH environment variable. * Open a console and go to your jasperReports/demo/barbeque folder. * Set the ant library to the lib folder by doing: ant -lib lib * Compile the barbecue report by doing: ant compile * Now create a jar file by doing: jar cfv bbqRenderer.jar -C build\classes net

To show barcodes in iReport we need to add the barbecue library and the newly created class to the classpath:

  • Open iReport. * Go to “Tools/Options” and select the “Classpath”-tab. * Click “Add JAR”. * Browse to the location where you saved “barbecue-1.0.6b.jar” (version number might differ) and open it:
  • Click “OK” to close the “Options” dialog. * Also Add the newly created bbqRenderer.jar in the same way.

Now we want to show a barcode on a report:

  • Open the “BarbecueReport.jrxml” (or create a new report). * A barcode is actually an image that is renderd by the library, so to add a barcode to the report we have drag an image from the “Report Elements” to the report. * Press “Cancel” if iReport asks for a path to the image file. * Select the newly added image. * In the “Image Properties” set the “Expression Class” to: net.sf.jasperreports.engine.JRRenderable * To display a barcode for “0123456789”, set the “Image Expression” to: new net.sf.jasperreports.renderers.BarbecueRenderer(BarcodeFactory.createCode128B("1234567890"))
  • Go to the “Preview” view, the barcode(s) should be visible: