9

Has anyone gotten the "Open Source QR Code Library" to work with ColdFusion? I need to generate QR Codes in ColdFusion.

I also found this tutorial on how to generate it using Zxing.

But the tutorial is not clear on how to configure the files, e.g. what needs to be in which dir...

Any help and alternatives are welcomed, thanks.

Adam Tuttle
  • 19,505
  • 17
  • 80
  • 113
n_kips
  • 585
  • 11
  • 20

3 Answers3

11

Zxing uses two (2) jars: core.jar and javase.jar. The easiest way to install them is to place both jars anywhere in the CF classpath (example: C:\ColdFusion8\wwwroot\web-inf\lib). Then restart the CF server. That is it.

Note: You can either compile the zxing jars yourself or download a slightly older version from this handy entry on blog.getRailo.com) Update: The barcode_samples.zip file does contain sample CF code. But it is for Railo only. Adobe CF does not support the extra parameters for createObject("java"). To use the code in Adobe CF, you need to remove the extra parameters.

<!--- Railo syntax --->
<cfset object = createObject('java','path.to.classtoinvoke','/path/to/jar/file/on/system')>
<!--- Adobe CF --->
<cfset object = createObject('java','path.to.classtoinvoke')>

If you do not have access to the classpath, you can use the JavaLoader.cfc to load the two (2) zxing jars instead. Just download the project. It includes some pretty good examples on installation and usage. But if you have further questions, let me know.

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • Thanks for the info. I pasted the two files in web-ini\lib and this is what I get when I run the Zxing's index.cfm ERROR: Unable to generate barcode The java object type is unknown for the CreateObject function. Any Ideas? – n_kips Nov 15 '10 at 11:49
  • @n_kips - The `code` samples are for Railo only. If you are running ACF you need to make some adjustments. Please see my updated comments above. – Leigh Nov 15 '10 at 15:18
  • @marc esher the code was the un-tempered barcode_samples.zip & Leigh got to the bottom of it. – n_kips Nov 15 '10 at 20:09
3

Essentially wrap the google API.

Here is the core of the code:

<cfhttp method="Get" url="http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=#url.text#" getAsBinary = "yes">

Click here to see my blog post for further detail

SOfanatic
  • 5,523
  • 5
  • 36
  • 57
1

I created a ColdFusion / jQuery QR code generator on my web site. Basically, you just send the info you want to convert in a URL string to Google. They create and host the image.

You can check it out on my site at http://www.EvikJames.com/?StackOverflow It's in the jQuery examples section, "Ajax QR Code Generator"

You can use the code below to see how I did it.

$(document).ready(function() {

$("#TextBox").keyup(updateImage);
$("#ImageSize").change(updateImage);

function updateImage() {
    var Message = $(this).attr("value");
    var ImageSize = $("#ImageSize").attr("value");
    $("#ResultImage").animate({ height: ImageSize, width: ImageSize}, 500);
    ImageSize = ImageSize + 'x' + ImageSize;
    MyURL = "https://chart.googleapis.com/chart?chs=" + ImageSize +  "&cht=qr&chl=" + Message;
    $("#ResultImage").attr("src", MyURL);
}

});
Evik James
  • 10,335
  • 18
  • 71
  • 122
  • 1
    +1 Yep. Google charts provides a simple interface to the zxing library. It can be a nice alternative for applications that do not need to keep the processing internal only. – Leigh Aug 26 '11 at 18:22
  • 1
    An you benefit from Google covering the bandwidth – Mike Causer Mar 02 '12 at 05:14