IREPORT+JS processing scan chinese QR code

Source: Internet
Author: User

Basic Application reference for Jasperreport:

Ireport+jasperreport+applet Report Printing


The idea and process of using ireport+jasperreport to deal with Chinese QR code is applied.

    1. Show the two-dimensional barcode in the report.

    2. Adaptive Scanner Action processing (Chinese escape).

    3. Combine JS to use barcode.


The first part shows the two-dimensional barcode in the report:

Reference: Generate two-dimensional barcode (QR code) in ireport

Idea: Apply the Zxing toolkit to generate a graphic of the QR code and write it in the image component of the ireport report.

Step 1: Download Core.jar and Javase.jar.

Step 2: Introduce ireport.

Open ireport, "Tools"-"Options"-"classpath", and then "Add jar", select the two jar files mentioned above.

Picture 1:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/8A/2B/wKiom1gpeA7ClTKEAAEF7vjEgxc192.png-wh_500x0-wm_3 -wmp_4-s_2131346976.png "title=" P1.png "style=" Float:none; "alt=" Wkiom1gpea7cltkeaaef7vjegxc192.png-wh_50 "/>

Add the image component and set the content expression, Figure 2:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/8A/2B/wKiom1gpeA-hdpvGAAEg7GcKMlQ824.png-wh_500x0-wm_3 -wmp_4-s_3024377226.png "title=" P2.png "style=" Float:none; "alt=" Wkiom1gpea-hdpvgaaeg7gckmlq824.png-wh_50 "/>

Expression content of an image component:

Com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage (

New Com.google.zxing.qrcode.QRCodeWriter (). Encode (

New String ($P {code}.getbytes ("UTF-8"), "iso-8859-1")

, com.google.zxing.barcodeformat.qr_code,100,100))

That is, the report parameter code is transcoded (handling Chinese garbled problem) after QRCode encoding and writing to the cached image object.

At the same time, in order to facilitate analysis at run time, we create 1 text boxes, the expression input is:

New String ($P {code}.getbytes ("UTF-8"), "iso-8859-1")

that is, the report parameter code transcoding results are entered into the text box.


Operation effect, figure 3: Parameter code input "test Kanji 1"

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8A/27/wKioL1gpeBDSmz71AAC2-NVGW9I941.png-wh_500x0-wm_3 -wmp_4-s_867612818.png "title=" P3.png "style=" Float:none; "alt=" Wkiol1gpebdsmz71aac2-nvgw9i941.png-wh_50 "/>

When the QR code is scanned on the phone, it can be identified. Picture 4:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/8A/28/wKioL1gpeaXgRDqUAACPm2O__ZU998.png-wh_500x0-wm_3 -wmp_4-s_2363191452.png "title=" P4.png "alt=" Wkiol1gpeaxgrdquaacpm2o__zu998.png-wh_50 "/>

If it is based on a mobile phone as a terminal, it is already ready to use, if you use a scanner to read, there are new problems.


The second part adapts the scanner operation processing

Scanner processing of two-dimensional barcode will generally simulate keyboard input, and Chinese content can not be directly processed by the keyboard. In the operation of the picture 3, the text box displays the garbled content, is the content that the scanner receives the feedback, namely the scanner based on the keyboard input simulation is unable to handle the Chinese content of the QR code correctly.

Consider a way to salvation, the Chinese content of the "UTF-8 encoding string" into the character form of "iso-8859-1" encoding, the code of the two-dimensional code to modify the content, while adding a new text box to display the response content:

Java.net.URLEncoder.encode (

New String ($P {code}.getbytes ("UTF-8"), "iso-8859-1")

, "Iso8859-1")

In order to facilitate debugging, add echo text box, the expression is:

Java.net.URLDecoder.decode (

Java.net.URLEncoder.encode (

New String ($P {code}.getbytes ("UTF-8"), "iso-8859-1")

, "Iso8859-1")

, "Utf-8")

Slice 5:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/8A/2B/wKiom1gpeBHACjmoAAC2hll0TDA696.png-wh_500x0-wm_3 -wmp_4-s_1174709067.png "title=" P5.png "style=" Float:none; "alt=" Wkiom1gpebhacjmoaac2hll0tda696.png-wh_50 "/>

Its running effect slice 6:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/8A/27/wKioL1gpeBHzvvW2AADjdhwnYBo235.png-wh_500x0-wm_3 -wmp_4-s_1703504733.png "title=" P6.png "style=" Float:none; "alt=" Wkiol1gpebhzvvw2aadjdhwnybo235.png-wh_50 "/>

At this point, the content of the Chinese content in its UTF-8 encoded string appears in the QR code.



The third part of the combination of JS use bar code

After applying the barcode scanner to simulate keyboard input, the barcode value will be obtained in the text box of the Web page, in this case the value is "%e6%b5%8b%e8%af%95%e6%b1%89%e5%ad%971"

Use JavaScript function decodeuricomponent to reply to its Chinese content, Image 7:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/8A/2B/wKiom1gpeBKzT_x1AABcjXblRVk476.png-wh_500x0-wm_3 -wmp_4-s_2658732427.png "style=" Float:none; "title=" P7.png "alt=" Wkiom1gpebkzt_x1aabcjxblrvk476.png-wh_50 "/>



Ireport+js processing scanning Chinese QR code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.