iReport: adding QRCode to Jasper reports the easy way

After testing various complicated solutions to embed a QR Code into iReport Jasper reports, the easiest way I’ve found is this:

1) Put ZXing’s Core and JavaSE jars in the classpath (using Tools/Options/Classpath if compiling locally, or the classpath property if using Ant and net.sf.jasperreports.ant.JRAntCompileTask)

2) Add an image to your report with the following settings:

  • Expression Class:
    java.awt.Image
  • Image Expression :
    com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(
         new com.google.zxing.qrcode.QRCodeWriter().encode(
             $F{CONTENT_TO_ENCODE},
             com.google.zxing.BarcodeFormat.QR_CODE, 300, 300))

    Of course, replace $F{CONTENT_TO_ENCODE} with your actual content.

3) Compile the report and enjoy !