Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

jasper reports - QR Code integration in jasperReport

I am generating the JasperReport for my billing desktop application using JAVA but, I can't see the QR Code icon in the report in jasper 6.0.3 version; In the preview it is showing the QR Code, but not in the real report.

Please can anyone suggest the idea and QR Code JAR files?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...