C# : Unable to print data as unicode characters from MYSQL database

徘徊边缘 提交于 2019-12-06 03:12:20

Can anyone let me know what i am doing wrong here?!

You are using a visually-encoded font.

In this scheme, you press the comma key on the keyboard, and type a regular character U+002C COMMA ,. The text field is set in a font where the shape of a comma make it look like a Tamil Letter I, but it's still really a comma.

A comma will be stored in the database, and searching tools will match it as a comma; if you pull it back out of the database and display it in the Bamini font then it will look like a Tamil Letter I, but display it in any standard font, like the one you're using to inspect your database, and it will look like a comma.

Visually-encoded fonts are the way we used to cope with language scripts that didn't have a standard encoding, but they should not be used today—chuck Bamini in the bin.

Modern operating systems ship a native Tamil keyboard and font (eg under Windows, Nirmala UI). Using this approach, the user would type into a normal text field (that had no special font set) and get a real Unicode character U+0B87 Tamil Letter I , that should look just the same in the database and behave semantically appropriately.

After a long list of trials, i finally found an alternative solution to print tamil characters in my printer. Note: Hardware Tech support informed me that many thermal printers wont accept tamil characters that are sent through raw printer helper class.

So i designed a crsytal report and tried printing, which was immediate success. (My printer is 3inch thermal printer)

Put something like this in the connection string:

id=my_user;password=my_password;database=some_db123;charset=utf8;

And change Description to CHARACTER SET utf8 (or utf8mb4).

See this for more debugging: http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored

Something goes wrong with the UTF-8 encoding of the string. ",e;j_ah" for sure isn't the UTF-8 representation of your string. I recommend bypassing the UTF-8 feature of the DB altogether and use a simple BLOB type for your "Country" column, which stores a plain byte array of variable length. Then use the UTF-8 codec of .NET and encode/decode yourself, storing the encoded byte array in the BLOB column.

So change the declaration of "Country" to:

`Country` BLOB NOT NULL,   

Use Encoding.UTF8.GetBytes() and Encoding.UTF8.GetString() to encode/decode your Tamil strings.

Basically, Bamini is not unicode standard. It has it own encodings so whenever you read you need to decode it which means you need to set bamini font on the contents. when you try to print the system doesn't set to bamini font.

so solution should be either use unicode fonts instead of bamini or set bamini font while printing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!