2017-02-14 170 views
3
private void button1_Click(object sender, EventArgs e) 
    { 

     string str = "අම්මා"; 
     byte[] utf8Bytes = Encoding.UTF8.GetBytes(str); 
     String productLine = Encoding.UTF8.GetString(utf8Bytes); 

     PrintDocument p = new PrintDocument(); 

     p.PrintPage += delegate(object sender1, PrintPageEventArgs e1) 
     { 
      e1.Graphics.DrawString(productLine, new Font("Iskoola Pota", 18), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); 

     }; 
     try 
     { 
      p.Print(); 
     } 
     catch (Exception ex) 
     { 
      throw new Exception("Exception Occured While Printing", ex); 
     } 
    } 

此代码的工作,但我的文字是“අම්මා”,但它显示为这样අ්මමා”,请帮助我,它显示为正确的方法。“Iskoola Pota”是Unicode字体打印Unicode字体

+0

您是否尝试过使用'str'直接?如果你这样做的结果是什么? – Fildor

+0

没有UTF8编码相同输出අ්මමා –

+0

也许这可能有所帮助:http://stackoverflow.com/q/6198744/982149 – Fildor

回答

0

UTF-8不是unicode。当你在源代码中声明你的字符串时,这是unicode。在你的情况下,在转换过程中删除短声音的变音符号会丢失。更糟糕的事情可能发生,例如参见Unicode Conversion in c#

为什么要采用UTF-8的方式呢?怎么样一个简单的

e1.Graphics.DrawString(str, ... 

另外:你检查你的“校书”的字体是确定的,即可以显示免费的声乐米ම්,例如通过在Word中使用该字体?

0

使用TextRenderer.DrawText而不是Graphics.DrawString

TextRenderer.DrawText(e1.Graphics, "අම්මා", font, rectangle, Color.Black);