4
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);
        }
    }

This Code works, but my text is "අම්මා" but it show as this way අ්මමා" so please help me it show as correct way. "Iskoola Pota" is Unicode Font

2 Answers2

0

UTF-8 is NOT unicode. When you declare your string in the source code, that's unicode. In your case, the diacritic sign for removal of short vocal gets lost during conversion. But worse things can happen, see e.g. Unicode Conversion in c#

Why take the way via UTF-8 anyway? What about a simple

e1.Graphics.DrawString(str, ...

Also: did you check that your "School Book" font is OK, i.e. can show a vocal-free m ම්, e.g. by using that font in Word?

Community
  • 1
  • 1
Bernhard Hiller
  • 2,163
  • 2
  • 18
  • 33
0

Use TextRenderer.DrawText instead of Graphics.DrawString

TextRenderer.DrawText(e1.Graphics, "අම්මා", font, rectangle, Color.Black);
Prasanna
  • 4,583
  • 2
  • 22
  • 29