简体   繁体   English

C# ESC/POS 打印越南语

[英]C# ESC/POS Print Vietnamese

["

I have an application which print the receipt to receipt printer using ESC\/POS.<\/i>我有一个使用 ESC\/POS 将收据打印到收据打印机的应用程序。<\/b> It needs to support multi-languages.<\/i>它需要支持多语言。<\/b> Currently, I've tested with Chinese characters (both traditional and simplified) and Thai language.<\/i>目前,我已经用中文(繁体和简体)和泰文进行了测试。<\/b> They all are working fine.<\/i>他们都工作正常。<\/b><\/p>

However, when I tried to print Vietnamese, some of the characters are being replace by "?".<\/i>但是,当我尝试打印越南语时,一些字符被替换为“?”。<\/b><\/p>

Here is my code:<\/i>这是我的代码:<\/b><\/p>

public static readonly string ESC = "\u001B";
...
...
...
Encoding enc = Encoding.GetEncoding(1258); //vietnamese code page
string content = "Cơm chiên với các loại gia vị truyền thống làm cho lưỡi của bạn";
string toPrint = ESC + "t" + char.ConvertFromUtf32(94) + "\n" + Encoding.GetEncoding("Latin1").GetString(enc.GetBytes(str));  //code page 94 is for vietnamese (WPC1258). It is get from printer

I found the answer!我找到了答案! It is not my code, but limitation of CodePage 1258 (see Convert text to Latin encoding and decode back problem for Vietnamese ).这不是我的代码,而是 CodePage 1258 的限制(请参阅Convert text to Latin encoding and decode back question for Vietnam )。

The question still remains, how to print in Vietnamese?问题仍然存在,如何用越南语打印?

There is a guy name HICURIN that managed to solve the problem (see Print Unicode Characters to POS printer ).有一个名叫 HICULIN 的家伙设法解决了这个问题(请参阅将Unicode 字符打印到 POS 打印机)。 Hopefully, he will be kindly to share his code with us.希望他能与我们分享他的代码。

Cheers, Sam干杯,山姆

["

This is all you need to be able to correctly print out Vietnamese characters on your printouts using C#<\/i>这就是使用 C# 在打印输出上正确打印越南字符所需的全部内容<\/b><\/p>

edit your code to this<\/i>将您的代码编辑为此<\/b><\/p>

public static readonly string ESC = "\u001B";
...
...
...
//Encoding enc = Encoding.GetEncoding(1258); //vietnamese code page
string content = "Cơm chiên với các loại gia vị truyền thống làm cho lưỡi của bạn";
string toPrint = ESC + "t" + char.ConvertFromUtf32(94) + "\n"; 
// First you need to convert the vietnamese string to utf-8 bytes.
byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(content); 
// Convert utf-8 bytes to a string.
toPrint += System.Text.Encoding.UTF8.GetString(utf8Bytes);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM