Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 685
AngelJanniee Avatar asked Apr 22 '15 01:04

AngelJanniee


2 Answers

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

like image 152
Kamal Singh Avatar answered Oct 16 '22 09:10

Kamal Singh


Finally I found the answer for this question,

We need to use the jar files to import the inbuilt jasperReport QR Code These are the jar files to generate the QR Code with Jasper report.

enter image description here

Also this jar files working for the jasper report without any exceptions.

then we have to drag and drop the QR-Code from the jasper report Elements. and then we can define specified parameters using the xml.

       <componentElement>
            <reportElement x="547" y="-5" width="115" height="83" uuid="f5bf25f8-2967-4e4e-bfa2-7879a3275e1c"/>
            <jr:QRCode xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                <jr:codeExpression><![CDATA["Customer No: " + $F{CUST_NO}]]></jr:codeExpression>
            </jr:QRCode>
        </componentElement>

Its working for me.

like image 4
AngelJanniee Avatar answered Oct 16 '22 09:10

AngelJanniee