in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Some foreign characters not rendering correctly when using DrawString()

Last post 02-07-2008 6:32 AM by centennial. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-26-2007 12:00 PM

    Some foreign characters not rendering correctly when using DrawString()

    I am integrating PDF support into our company's product at the moment, and for the most part it is working fine. Quite often, we need to add non-UK characters to the exported PDF. This works for mainland European character strings like "éâàâÔ", but does not appear to work for strings from further afield. The sample string I tried was:

    أداة إزالة البرامج الضارة لـ

    (Don't ask me what it means or what language it is, something to do with Microsoft)

    This renders as

    ???? ????? ??????? ?????? ??

    I have also tried using DrawStringRtf(), but that just displays it as a blank.

    Is there a setting I need to change to allow full UTF-8 support?

    Thanks

  • 10-26-2007 12:06 PM In reply to

    Re: Some foreign characters not rendering correctly when using DrawString()

    Here's a cut down version of the code: 

    Font font = new Font("Arial", 8);
    
    // center vertically
    StringFormat sform = new StringFormat();
    sform.Alignment = StringAlignment.Near;
    sform.LineAlignment = StringAlignment.Center;
    
    myPDFObject.DrawString(text, font, Brushes.Black, rcCell, sform);
    
  • 10-30-2007 4:28 PM In reply to

    Re: Some foreign characters not rendering correctly when using DrawString()

    Font management in pdf is not trivial. Some languages require special font
    packages to be installed (Chinese, Korean, etc).

    Can you post or e-mail me a program that draws the string in question into a
    panel or form? That way I could see exactly what the string looks like and
    what happens when C1Pdf renders it.

    Thanks in advance.



    wrote in message news:199287@10.0.1.98...
    > Here's a cut down version of the code:
    >
    > Font font = new Font("Arial", 8);
    >
    > // center vertically
    > StringFormat sform = new StringFormat();
    > sform.Alignment = StringAlignment.Near;
    > sform.LineAlignment = StringAlignment.Center;
    >
    > myPDFObject.DrawString(text, font, Brushes.Black, rcCell, sform);
    >
  • 10-31-2007 6:50 AM In reply to

    Re: Some foreign characters not rendering correctly when using DrawString()

    Attached is a test I've knocked up, hope it's useful (C# console application, writes a PDF to c:\TestHarness)

     I tried to attach the whole solution as a zip, but it failed for some reason, so here' the source code:

     

    using System;

    using System.Data;

    using System.Drawing;

    using System.IO;

    using C1.C1Pdf;

     

    namespace ForeignLanguagePDFTestHarness

    {

    class Program

    {

    static void Main(string[] args)

    {

    #region Initialize PDF

    C1PdfDocument pdf = new C1PdfDocument();

    // create pdf document

    if (pdf.Pages.Count < 1)

    pdf.NewPage();

    // calculate page rect (discounting margins)

    RectangleF rcPage = pdf.PageRectangle;

    rcPage.Inflate(-72, -72);

    #endregion

    #region
    Add foreign text

    string text = "أداة إزالة البرامج الضارة لـ";

    using (Font font = new Font("Arial", 10, FontStyle.Regular))

    {

    // draw the string

    pdf.DrawString(text, font, Brushes.Black, rcPage);

    }

    #endregion

    #region
    Save file

    string outDir = @"c:/TestHarness";

    try

    {

    if (!Directory.Exists(outDir))Directory.CreateDirectory(outDir);

    }

    catch (Exception e)

    {

    Console.WriteLine("Could not create directory \"{0}\" for test output", outDir);

    Console.WriteLine("Message: {0}", e.Message);

    }

    try

    {

    pdf.Save(
    string.Format("{0}/TestFile.pdf", outDir));Console.WriteLine("File written to {0}", outDir);

    }

    catch (Exception e)

    {

    Console.WriteLine("Could not save the test file to directory \"{0}\".", outDir);

    Console.WriteLine("Message: {0}", e.Message);

    }

    //Pause the application

    Console.Write("Finished, press any key to close... ");

    Console.Read();

    #endregion

    }

    }

    }

  • 10-31-2007 7:40 AM In reply to

    Re: Some foreign characters not rendering correctly when using DrawString()

    It might be worth mentioning that I'm having similar problems with Japanese characters:

     のソフトウェア just renders as ???????

    アプリケーション拡張 partially renders, it comes out as ????ー???拡?

    I have support for East Asian languages turned on for my OS (Windows XP), and also support for complex script and right-to-left languages.

     I also use your XLS component to export the same data, but that works fine.

  • 11-13-2007 4:45 AM In reply to

    Re: Some foreign characters not rendering correctly when using DrawString()

     

  • 02-07-2008 6:32 AM In reply to

    Re: Some foreign characters not rendering correctly when using DrawString()

    Have solved this now, added the following line:

     pdf.FontType = FontTypeEnum.Embedded;

    where 'pdf' is the C1PdfDocument instance you are using 

Page 1 of 1 (7 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.