Create a 2D Datamarix Barcode Using ColdFusion and Barcode4j with Unicode

Most barcode readers do not support Unicode. Barcode readers connected to a USB or a keyboard port are able to supply only the characters available on the keyboard. This is because the barcode readers act much like keyboards. Most Unicode characters require additional processing through uniscribe before they can be rendered on the screen. Even Windows XP fails to provide complete uniscribe for most languages. Simple barcode readers definitely cannot process Unicode directly. However, we can always encode Unicode, or any other special characters, into simple formats. Then we can decode them once we have read the data in our application. Of course, that is the problem––if we encode, we have to decode, and the client application has to be able to decode accordingly.

My favorite method is URLEncodedFormat() because it is so simple. It converts the Unicode string "你好" into %E4%BD%A0%E5%A5%BD, which will go perfectly into a barcode. I can simply use URLDecode() to decode back again once it has been read. The disadvantage of this method is that it needs to be processed by ColdFusion. If your barcode is read by some other application, this method may not work.

Barcode applications generally prefer to convert special characters and Unicode into Decimal Points, such as "你好" into 你好. Most displaying applications, including browsers, are capable of decoding those decimal points back to a representative character without any extra work. I created this function to convert special characters and Unicode into decimal points.

   1: <cffunction
   2:  name        = "toDecimalPoint"
   3:  returntype = "string"
   4:  output     = "no"
   5:  description = "Convert Unicode in to Decimal HTML Friendly Entry points">
   6:     <cfargument name="string" required="Yes" type="string">
   7: 
   8:  <cfset newString = "">
   9:  <cfloop from="1" to="#len(arguments.string)#" index="i">
  10:  <cfset thisChr    = mid(string,i,1)>
  11:     <cfset deci    = asc(thisChr)>        
  12:  <cfif deci gt 4096>
  13:     <cfset newString = "#newString#&###Ucase(FormatBaseN(deci,10))#;">
  14:     <cfelseif deci gt 255>
  15:     <cfset newString = "#newString#&##0#Ucase(FormatBaseN(deci,10))#;">
  16:     <cfelseif deci gt 127>
  17:     <cfset newString = "#newString#&##00#Ucase(FormatBaseN(deci,10))#;">
  18:     <cfelse>
  19:     <cfset newString = "#newString##thisChr#">
  20:     </cfif>
  21:  </cfloop>
  22: 
  23:  <cfreturn newString>
  24: </cffunction>
Show/Hide Line Numbers . Full Screen . Plain

Here is an example




Once the encoding is done, you can pass them in to the Datamatrix BarCode4j Coldfusion wrapper in here.