Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
753 views
in Technique[技术] by (71.8m points)

c# - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 : ? ? ? ? ? ü 
" +
 " 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...