Andy M
Andy M

Reputation: 6065

iTextSharp displaying greek chars

I'm trying to display the sigma char into a PDF generated by code in my C# (Framework 4) application. I'm using iTextSharp (V. 4.1.2.0).

Whenever I try and print my char using the following snippet...

string l_sTmpText = "\u03A3";
l_table.AddCell(new Phrase(l_sTmpText, MyFont));

...I get nothing but a blank space in my PDF. When going in debug, My sigma char is properly display within Visual Studio so I suspect this is an encoding problem.

I've found and read this post : iTextSharp international text...

...But I still cannot manage to make it work. I tried to create a BaseFont like this :

private static BaseFont MySpecialBaseFont = iTextSharp.text.pdf.BaseFont.CreateFont("C:\Windows\Fonts\Arial.ttf", iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.EMBEDDED);

My problem is the construction of a Phrase object requires a Font and not a BaseFont. I'm stuck around here...

Upvotes: 1

Views: 1591

Answers (1)

Andy M
Andy M

Reputation: 6065

I've found my mistake... The beginning was right :

private static BaseFont MySpecialBaseFont = iTextSharp.text.pdf.BaseFont.CreateFont("C:\\Windows\\Fonts\\Arial.ttf", iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.EMBEDDED);

I then had to create a font (I was stuck there) from my BaseFont :

private static Font MySpecialCharfont = new iTextSharp.text.Font(MySpecialBaseFont);

I can then create my Phrase object :

new Phrase(l_sTabulationString + l_sTmpText.ToLowerInvariant(), MySpecialCharfont)

Please note the ToLowerInvariant() that allowed me to get a lowerCase version of the sigma char. Hope this will help someone else...

Upvotes: 3

Related Questions