Anıl Aşık
Anıl Aşık

Reputation: 351

Created PDF file is missing characters in Turkish language

Well, I am trying to export some data from my WinForms application to a PDF file. I have downloaded some fonts which support Turkish language characters. In the Turkish language, there are some letters like ç,ğ,ş,ö,ü,ı. My code has no problems with showing ç,ö,ü but somehow when the user inputs ğ, ş or ı, these letters get represented as blank in the PDF file.

My code is below:

Document doc= new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri=PdfWriter.GetInstance(doc, new FileStream("Test.pdf", FileMode.Create));
doc.Open();

BaseFont bf = BaseFont.CreateFont(@"C:\aller.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
Paragraph p1 = new Paragraph(new Chunk("çğşöüı", font));

doc.AddLanguage("tr-TR");
wri.SetLanguage("tr-TR");
doc.Add(p1);
doc.Close();

So, where is my mistake?

Upvotes: 1

Views: 2016

Answers (1)

Anıl Aşık
Anıl Aşık

Reputation: 351

after tryings, I found the answer;

BaseFont bF = BaseFont.CreateFont("C:\\windows\\fonts\\arial.ttf", "windows-1254", true);
 iTextSharp.text.Font f = new iTextSharp.text.Font(bF, 12f, iTextSharp.text.Font.NORMAL);
 Chunk c = new Chunk();
 c.Font = f;
 iTextSharp.text.Document document = new iTextSharp.text.Document();
 PdfWriter.GetInstance(document, new FileStream(@"C:\gorsel.pdf", FileMode.Create));
 string text = "küçük harf türkçe karakterler : ç ğ ı ö ş ü \n" +
 " BÜYÜK TÜRKÇE KARAKTERLER : Ç Ğ İ Ö Ş Ü";
 c.Append(text);
 document.Open();
 document.Add(new Paragraph(c));
 document.Close();

now I can use all special characters in my PDF file.

Upvotes: 2

Related Questions