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()

rated by 0 users
This post has 7 Replies | 1 Follower

Not Ranked
Posts 6
centennial Posted: Fri, Oct 26 2007 12:00 PM

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

Not Ranked
Posts 6
centennial replied on Fri, Oct 26 2007 12:06 PM

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);
Top 10 Contributor
Posts 2,707
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);
>
Not Ranked
Posts 6

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

}

}

}

Not Ranked
Posts 6

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.

Not Ranked
Posts 6

 

Not Ranked
Posts 6

Have solved this now, added the following line:

 pdf.FontType = FontTypeEnum.Embedded;

where 'pdf' is the C1PdfDocument instance you are using 

Not Ranked
Posts 1
Tyzack replied on Wed, Nov 26 2008 4:38 PM

Has anyone seen this using:

                         // Draw the PDF
                        c1pdf.DrawImage(img, c1pdf.PageRectangle);

 

instead of DrawString?

Page 1 of 1 (8 items) | RSS
Contact ComponentOne: 1.800.858.2739 ©1987-2010 ComponentOne LLC All Rights Reserved.