Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
also im found Code 128 fully functional barcode generator http://www.mbcestore.com.mx/generador/codigo-de-barras/, just linked to my webservice/CFapp and im request string and return image with barcode very usefull
Copy link to clipboard
Copied
Newsgroup_User wrote:
Does anyone know of a free or 'cheap' barcode generator that will work with CF?
Copy link to clipboard
Copied
Newsgroup_User wrote:
Does anyone know of a free or 'cheap' barcode generator that will work with CF?
Hello one and all,
ColdFusion can go even one better. You can use the iText library, which currently ships with ColdFusion, to generate barcodes!
Here is a proof of concept:
<cfscript>
codeEAN = createobject("java","com.lowagie.text.pdf.BarcodeEAN");
codeEAN.setCodeType(codeEAN.EAN13);
codeEAN.setCode("4902555131719");
color = createobject("java","java.awt.Color");
image = codeEAN.createAwtImage(color.black, color.white);
bufferedImage = createObject("java", "java.awt.image.BufferedImage");
bufferedImageType = bufferedImage.TYPE_BYTE_GRAY;
bufferedImage = bufferedImage.init(image.getWidth(JavaCast("null", "")),image.getHeight(JavaCast("null", "")), bufferedImageType);
graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(image,0,0,JavaCast("null", ""));
barcodeImage = imageNew(bufferedImage);
</cfscript>
<cfimage action="writeToBrowser" source="#barcodeImage#" format="jpg">
Copy link to clipboard
Copied
Nice job! One shortcut you could add is grabbing the graphics object from the CF image instead of creating a new bufferedImage (slight savings). That is a trick I have used in the past:
ie ...
width = image.getWidth(JavaCast("null", ""));
height = image.getHeight(JavaCast("null", ""));
cfImage = imageNew("", width, height);
graphics = ImageGetBufferedImage(cfImage).getGraphics();
graphics.drawImage(image,0,0,JavaCast("null", ""));
Copy link to clipboard
Copied
Hi BKBK,
Since I found your post I'm looking for documentation on the iText Coldfusion's library sintax. I'll try to generate Code128C barcodes but not found the exact sintax based on your code.
Thanks in advance.
Copy link to clipboard
Copied
See the iText API for Barcode.
An example:
<cfscript>
code128= createobject("java","com.lowagie.text.pdf.Barcode128");
code128.setCodeType(code128.CODE128);
/* Set the code to generate */
code128.setCode("0123456789");
color = createobject("java","java.awt.Color");
image = code128.createAwtImage(color.black, color.white);
bufferedImage = createObject("java", "java.awt.image.BufferedImage");
bufferedImageType = bufferedImage.TYPE_BYTE_GRAY;
bufferedImage = bufferedImage.init(image.getWidth(JavaCast("null", "")),image.getHeight(JavaCast("null", "")), bufferedImageType);
graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(image,0,0,JavaCast("null", ""));
barcodeImage = imageNew(bufferedImage);
</cfscript>
<!--- Output the code as an image --->
<cfimage action="writeToBrowser" source="#barcodeImage#" format="jpg">
Copy link to clipboard
Copied
Great! It works like a charm!
However I don't understand how to apply the API specifications you point me to, to the ColdFusion script.
I try to set the height and the width of the barcode but haven't seen where and how.
If I could take advantage of your knoledge one more time... 😉
Thanks in advance.
Copy link to clipboard
Copied
If you ever need QR codes you can use my project on riaforge http://qrtoad.riaforge.org/ It could do barcodes too.. just been too lazy to add it.
Copy link to clipboard
Copied
It looks great! If I never need QR i will use it.
Now I still need to solve my barcode size problems.
Thanks.
Copy link to clipboard
Copied
I had a look at the API and I can't see how to set the barcode width. I can set its height with "code128.setBarHeight(x);" but none of the parameters I tried (setX, setN...) seems to affect the overall size of the barcode and, as it gets rendered, it's unusable because the bars are too close to be read once printed.
I don't know where to look further.
If I use Coldfusion's ability to resize the resulting image, the result is too fuzzy because the bars become blured and the barcode reader can't read them properly.
I'm stuck!
Any suggestion will be much appreciated.
Thanks in advance.
Copy link to clipboard
Copied
Solved with Barbecue http://barbecue.sourceforge.net !!
Thnaks.
Copy link to clipboard
Copied
Very cool.
Copy link to clipboard
Copied
Check this free version of barcode generator:http://www.onbarcode.com/tutorial/vb-net-barcode-create-net-windows.html
Copy link to clipboard
Copied
<cfimage action="writeToBrowser" source="#barcodeImage#" format="jpg" width="400" height="100">
Copy link to clipboard
Copied
I copied the code and it does create a barcode, awesome. How do you set a varabile for the barcode?
Copy link to clipboard
Copied
I copied the code and it does create a barcode, awesome. How do you set a varabile for the barcode?
By @philr3814055
A variable has already been set for it. 🙂 The name of the variable is barcodeImage.
For example, if you wished to save the barcode as a Jpeg file, you could do something like this at the end:
<!--- Saves barcode to current directory --->
<cfimage action="write" destination="#expandpath('myBarcode.jpg')#" source="#barcodeImage#"