How to Generate & Recognize Barcodes for UTF 8 (Unicode) Characters using Java

This technical tip shows how to generate and recognize barcodes for UTF 8 (Unicode) characters inside Java apps using Aspose.Pdf for Java. UTF-8 is a variable length character encoding for Unicode. It can represent any character in the Unicode standard. You can generate barcodes for non-English characters, for example Arabic, Latin, Greek etc. Aspose.BarCode is a Java based visual component for generation & recognition of 1D & 2D barcodes to support Java and web applications. It supports 29+ barcode symbologies like MSI, QR, OneCode, Australia Post, Aztec, Code128, Code11, EAN128, Codabar, Postnet, USPS and also supports image output in GIF, PNG, BMP & JPG formats. This article shows how. The sample code below generates a barcode for Arabic character and then recognizes it back from the image.
//your code here..[Java] import com.aspose.barcode.*; import com.aspose.barcoderecognition.BarCodeReadType; import com.aspose.barcoderecognition.BarCodeReader; import java.awt.Toolkit; import java.io.UnsupportedEncodingException; public class RecognitionUnicode { public static void main(String[] args) throws UnsupportedEncodingException { try { License lic = new License(); lic.setLicense("e:\\ aspose.barcode.lic"); } catch(Exception ex) { System.out.println(ex.getMessage()); } String file = "pdf417_un.png"; String scodeText = "????"; System.out.println("codetext: " + scodeText); String codeText = getCodeTextFromUnicode(scodeText); BarCodeBuilder builder = new BarCodeBuilder(Symbology.PDF417, codeText); builder.save(file); BarCodeReader r = new BarCodeReader(file,BarCodeReadType.getPdf417()); boolean rb = r.read(); String rc = r.getCodeText(); try { String s = getUnicodeFromCodeText(rc); System.out.println(s); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } r.close(); } private static String getCodeTextFromUnicode(String s) throws UnsupportedEncodingException { byte[] bs = s.getBytes("UTF-8"); StringBuffer buf = new StringBuffer(); for (int i = 0; i < bs.length; i++) { byte b = bs[i]; if(b >=0) { buf.append((char)b); } else { buf.append((char)(127 - b)); } } return buf.toString(); } private static String getUnicodeFromCodeText(String cs) throws UnsupportedEncodingException { byte[] bs = new byte[cs.length()]; for(int i=0; i< cs.length();i++) { char c = cs.charAt(i); if(c < 128) { bs[i] = (byte) c; } else { bs[i] = (byte) (127 - c); } } return new String(bs," UTF-8"); } } .

Url: http://www.aspose.com/java/barcode-component.aspx

Language: Java | User: Sheraz Khan | Created: Jun 10, 2015 | Tags: generate barcode for UTF 8 characters recognize UTF 8 characters barcodes recognize UTF 8 characters barcodes recognize UTF 8 characters barcodes generate barcode with Unicode characters generate barcode with Arabic characters Java Barcode API generate barcodes for non-English characters