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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//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[] argsthrows 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.PDF417codeText);
        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 sthrows UnsupportedEncodingException {
        byte[] bs = s.getBytes("UTF-8");
       StringBuffer buf = new StringBuffer();
        for (int i = 0i < bs.lengthi++) {
            byte b = bs[i];
            if(b >=0)
            {
                buf.append((char)b);
            }
            else
X

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