I am writing my answer very late. But I think zxing is the best open source library for generating the QR code. Here I am writing how you can generate QR code using zxing library in Java. I am using iReport as designer tool.
Step 1: Add 2 jar files in class path of iReport (Tools > Options > iReport Tab > Classpath Tab > Add Jar)
a) zxing-core
from https://mvnrepository.com/artifact/com.google.zxing/core/3.3.1
b) zxing-javase
from https://mvnrepository.com/artifact/com.google.zxing/javase/3.3.1
Note: You may choose latest jar's. I am using latest as of date
Screen shot of adding jar in class path
Step 2: Create a parameter / field (as per your need). I am using a parameter. Let us call it qrCode.
Step 3: Drag and drop an image from palette panel of iReport designer (In windows it is accessible through Shift + ctrl + 8
). And choose Cancel (We do not want static image).
Step 4: Select the image by clicking on it. You will see the properties tab in right side.
a) Choose Expression Class as java.awt.Image
b) Click on Image Expression property. And fill the expression as
com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(
new com.google.zxing.qrcode.QRCodeWriter().encode(
$P{qrCode},
com.google.zxing.BarcodeFormat.QR_CODE, 300, 300
)
)
Note: If you want to use field
instead of parameter
just replace the parameter
with field
in expression.
Screen shot of steps
Step 5: Compile report and run.
To read about different usage go through the post Generate QR code in Java using zxing
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…