QRCode

1
0
-1

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

Comments

Submitted by Sean McP on Wed, 12/10/2014 - 14:48

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

2 answers

1
+1
-1

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

Comments

Submitted by yborf on Thu, 12/11/2014 - 09:13

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

Submitted by Sean McP on Thu, 12/11/2014 - 09:16

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

Submitted by yborf on Thu, 12/11/2014 - 09:29

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

Submitted by Sean McP on Thu, 12/11/2014 - 09:54

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

Submitted by yborf on Thu, 12/11/2014 - 14:09

thank you for the interesting link. but error on

package net.viralpatel.qrcode;

Regards

Submitted by Sean McP on Thu, 12/11/2014 - 17:29

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

Submitted by yborf on Fri, 12/12/2014 - 11:23

thank you very much for your patience, again

I've found that http://stackoverflow.com/questions/9257038/how-to-create-qrcode-using-ja...

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...

but without success too

regards

Submitted by Sean McP on Fri, 12/12/2014 - 14:42

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

Submitted by yborf on Fri, 12/12/2014 - 15:40

thank you very much now it works Regards

Submitted by Sean McP on Fri, 12/12/2014 - 15:42

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

Submitted by yborf on Fri, 12/12/2014 - 15:53
  • 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

Submitted by delinare.its on Sun, 12/25/2016 - 21:59

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

Submitted by Sean McP on Mon, 12/26/2016 - 19:08

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

regards

Submitted by delinare.its on Sun, 02/19/2017 - 06:19

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

1
0
-1

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?

Notifications