QRCode

I’m trying to generate a QRCode (in email , png file , any method is accepted), but I’m not able to get it working.
I’m using Bonita Community 6.3.9.

importing QRCode connector fails.
then I’m trying with the following groovy script

import com.google.zxing.* import com.google.zxing.qrcode.* import com.google.zxing.qrcode.decoder.* import com.google.zxing.client.j2se.* import javax.imageio.ImageIO import java.awt.image.BufferedImage import java.awt.*

//fix zxing dependency
@Grapes(
@Grab(group=‘com.google.zxing’, module=‘javase’, version=‘2.2’)
)

def QRCODE_IMAGE_HEIGHT = 300
def QRCODE_IMAGE_WIDTH = 300
//path where you want to save qrcode
def IMAGE_PATH = “C:/”

def hints = new HashMap()
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H)

def qrWriter = new QRCodeWriter()
//Add your data instead of http://www.google.com
def matrix = qrWriter.encode(“http://www.google.com”,
BarcodeFormat.QR_CODE,
QRCODE_IMAGE_WIDTH,
QRCODE_IMAGE_HEIGHT,
hints)

def image = MatrixToImageWriter.toBufferedImage(matrix)

//Draw the new image
def combined = new BufferedImage(QRCODE_IMAGE_HEIGHT, QRCODE_IMAGE_WIDTH, BufferedImage.TYPE_INT_ARGB)
def g = (Graphics2D)combined.getGraphics()
g.drawImage(image, 0, 0, null)

def imageFile = new File(IMAGE_PATH, “qrcode_logo2.png”)
ImageIO.write(combined, “PNG”, imageFile)

that gives the Runtime exception: could not find matching construct

try - Line 22 - def qrWriter = new QRCodeWriter) what is the ) doing there?

This is because of a mismatch of the version of the QR and ZZ libraries.

It’s painful why so many JARs are out there and out of sync.

Can’t someone just package the solution correctly?

I’m not used to groovy but I see no try{} catch(){} blocks…

one which statement do you think you get this error message?

see here

regards

I apologize, cut and paste error. now fixed the script

So it’s working now? Hope so 'cause I might want to use this one day…

not yet. The only way I’m able to generate a QRcode in a email is by a free on line generator like this:

http://api.qrserver.com/v1/create-qr-code/?data=HelloWorld&size=100x100

Bugger I closed the wrong tab,

If you’re trying to use the Bonita QRcode generator from 2011 it may not work with version 6…

Best one I found was to do it via “java/groovy” script here.

http://viralpatel.net/blogs/create-qr-codes-java-servlet-qr-code-java/

regards

have a look at

thank you for the
interesting link. but
error on

package net.viralpatel.qrcode;

Regards

Yes, you would,

Your supposed to modify the code…

I’m not doing it for you but this may work with some tweaking in a script connector…

import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import net.glxn.qrgen.QRCode; import net.glxn.qrgen.image.ImageType;

ByteArrayOutputStream out = QRCode.from(“Hello World”).to(ImageType.PNG).stream();

    try {
        FileOutputStream fout = new FileOutputStream(new File("C:\\QR_Code.JPG"));

        fout.write(out.toByteArray());

        fout.flush();
        fout.close();

    } catch (FileNotFoundException e) {
        // Do Logging
    } catch (IOException e) {
        // Do Logging
    }

don’t forget to add the necessary JARs to the LIB or as a resource to your application.

good luck
regards

thank you very much for your patience, again

I’ve found that
http://stackoverflow.com/questions/9257038/how-to-create-qrcode-using-java-j2se
It’s very simple , but I’m not able to get It working
error : java.lang.NoSuchMethodError: com.google.zxing.Writer.encode(Ljava/lang/String;Lcom/google/zxing/BarcodeFormat;IILjava/util/Map;)Lcom/google/zxing/common/BitMatrix;
I’m doing something wrong, but I don’t know

I’m trying also to make use of this
https://github.com/tyanhly/QRCode/blob/master/grails-app/services/grails/plugins/qrcode/QRCodeService.groovy
but without success too

regards

Yeah!!!

I should be working but this was annoying me as I had the same problem.

I’ve now fixed it…

Basically all the same code but I had to use the correct JARS as linked for download:

core-3.1.0.jar
javase-3.1.0.jar
qrgen-1.4.jar

Good QRHunting…

regards

thank you very much
now it works
Regards

What’s your final code look like? I can’t get it to save on my file space Access Errors?

Thanks for sharing.

regards
Seán

  • removed old JARs
  • replaced with ones from the above link
  • respect to your original code I’ve changed the path (desktop rather than C:\ ), because of a privilege exception.

    ByteArrayOutputStream out = QRCode.from(“Hello World”).to(ImageType.PNG).stream();

try {
FileOutputStream fout = new FileOutputStream(new File(“C:\…\Desktop”));

fout.write(out.toByteArray());

fout.flush();
fout.close();

} catch (FileNotFoundException e) {
// Do Logging
} catch (IOException e) {
// Do Logging
}

good work
Regards

hello, Im new in Bonita and I want to know how to use this jar. Where should I put those code to make QRcode.jar works?

Thanks before.
Regards

You add the necessary JARs to the \LIB folder or as a resource to your application.

regards

Sorry, I want to ask again.
Actually, it works when I run it with ‘evaluate’ button in connectors out box and set the necessary JARs manually! (as seen in pict below) 1

could it be automatically because I want to use it to generate qrcode based on user input? I’ve put it in LIB folder (C:\BonitaBPMCommunity-7.3.2\jre\lib).

Thanks in advance.

regards,
Delina