Search code examples
javajasper-reportszxing

Encoding QR Code with UTF-8 as an image on JasperReports


I tried to encode some text on languages such as Vietnamese, Russian to QR Code in JasperReports following this post.

I'm using Zxing API. It's working ok for EN, US locales, but I faced issue with encoding text in Russian or Vietnamese.

I used this expression:

    com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(
        new com.google.zxing.qrcode.QRCodeWriter().encode(
   "французкий язык",
            com.google.zxing.BarcodeFormat.QR_CODE, 300, 300
        )
    )

The result of decoding is: ?????????? ????

How to fix this issue?


Solution

  • I found this way worked for me.

    com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(
        new com.google.zxing.qrcode.QRCodeWriter().encode(
           new String(("французкий язык").getBytes("UTF-8"), "ISO-8859-1"),
            com.google.zxing.BarcodeFormat.QR_CODE, 300, 300
        )
    )