2017-02-14 97 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);