QR Code integration in jasperReport

孤街浪徒 提交于 2019-12-29 07:44:09

问题


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?


回答1:


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




回答2:


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.

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.



来源:https://stackoverflow.com/questions/29786226/qr-code-integration-in-jasperreport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!