Summary

Use this CFC as a wrapper to access the java 2D BarCode libraries from Java4Less. To use this you'll need to purchase the related java libraries from Java4less - http://www.java4less.com. They do have a free evaluation version for download that will work fine for testing. I have no affiliation with them other than I needed to use their product in ColdFusion. Note that this class only deals with 2D/Data Matrix barcodes. Java4Less offers libraries for reading/writing regular barcodes, but I have not used them. Works on any image type that the ColdFusion cfimage tag can read.

The java libraries this works with are:
Reader: Datamatrix Vision for Java - evaluation version available from here
Writer: RBarcode for Java - evaluation version available from here

You'll need to copy the jar file in each of those archives to your {coldfusion-install-dir}/lib directory, or place them somewhere else and add the path to them in your java.class.path setting in jvm.config.

Requires

Usage

First create and initalize the object.

<cfset BarCoder = CreateObject("component","2DBarCode_j4l").init()>	

Reading Barcodes

There are two methods you can call to read a barcode: readFromImage() and readFromFile(). readFromImage() takes a ColdFusion image object as an argument. readFromFile() takes a string that is a path to the file to be read. All image types that the cfimage tag can read are supported.

<cfset results = BarCoder.readFromImage(myImageObject)>
or
<cfset results = BarCoder.readFromFile("myFile.png")>

The methods return an array of barcodes that were found in the image. Each element in the array contains the following structure:

Key Description
x The x coordinate of where the barcode was found on the image.
y The y coordinate of where the barcode was found on the image.
value The value that was read from the barcode.

If no barcodes were found, an empty array is returned.

Creating Barcodes

Basic example:

<cfset ImageObjContainingBarcode = BarCoder.createBarCode(text='my text to place into barcode')>
ImageContainingBarcode is now a ColdFusion image object, you can write it to file or sent it to the browser or whatever you need to do.

There are several more options that can be passed into the createBarCode method:

Argument Description Default
text The text to encode into a barcode.  
dotPixels The number of pixels that create each square in the barcode. (Use 2-7, see known issues) 4
encoding One of the following: E_ASCII, E_AUTO, E_BASE256, E_C40, E_NONE, E_TEXT. Only tested with E_ASCII. E_ASCII
preferredFormat Code representing the perferred generated barcode size. Barcode will expand beyond this if necessary. See perferredFormat codes below. C10X10
margin Pixels of margin around the barcode. Only used on the top and left sides. 0
width Width of the image containing the barcode 200
height Height of the image containing the barcode 200

preferredFormat Codes

C10X10 - 10 squares by 10 squares
C12X12 - etc.
C14X14
C16X16
C18X18
C20X20
C22X22
C24X24
C26X26
C32X32
C36X36
C40X40
C44X44
C48X48
C52X52
C64X64
C72X72
C80X80
C88X88
C96X96
C104X104
C120X120
C132X132
C144X144
C8X18
C8X32
C12X26
C12X36
C16X36
C16X48

Known Issues

1. If you try to create a barcode containing only a single character, you will get a java 'array out of bounds' error.

2. If you change the dotPixels value from the default of 4 be aware that I could only decode images that were created with a dotPixels value between 2 and 7. If you need a larger barcode that what dotPixels=7 will give you, you can try resizing the generated image with ImageResize(). This has proven reliable for me as long as the original image was created with a dotPixels of between 2-7. If you can explain why that is please email me!

3. If you are working with the evaluation versions of the Java4Less library, you will want to set your margin to 20 or higher so the barcode is not displayed on top of their evaluation warning message. (otherwise you probably won't be able to decode it)

Send feedback to ryan@cfwebtools.com