Search code examples
c#using

how to convert text readed from barcode to arabic text


I have barcode image with type "pdf417",it content a arabic text , When read it using barcode it through a text like this "ÃÍãÏ#" how can I convert this text to its original text (arabic)


Solution

  • If your method gives you a byte[] use:

    var str = Encoding.UTF8.GetString(yourBytes);
    

    or, perhaps

    var str = Encoding.GetEncoding(1256) // 1256 is the Windows Arabic codepage
                      .GetString(yourBytes);
    

    If your method gives you a string do this:

    // iso-8859-1 is a codepage that can be used to convert back some 
    // malformed unicode strings
    var str = Encoding.GetEncoding(1256)
                      .GetString(Encoding.GetEncoding("iso-8859-1")
                                         .GetBytes(yourString));
    

    The text you had in your question in the beginning was converted with this to:

    أحمد#المنير#محمد#فاطمه #حرستا 27-12-1949#
    

    Note that only the UTF8 format will make the barcode "universal" (because UTF8 can represent all the Unicode characters). The 1256 codepage will make your barcode "regional" (you have to know where your barcode was written to imagine it could be encoded with the 1256 Windows Arabic codepage)