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

Categories

I have string data which contains some english characters and some chinese characters. I m creating a pdf file with this data using iTextSharp. After pdf file is created, when i open it, pdf contains only english characters. It is not showing chinese characters. Can you please tell me how to display chinese characters in pdf file?. Please note that the string data that i m writing to pdf contains dynamic language characters i.e sometimes english, somethimes chinese, sometimes japanese and so on.

See Question&Answers more detail:os

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

1 Answer

This is explained in the iText(Sharp) documentation. When you have a String with glyphs from different languages, you need to use a FontSelector as shown in this example.

FontSelector selector = new FontSelector();
selector.AddFont(FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12));
selector.AddFont(FontFactory.GetFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED));
Phrase ph = selector.Process(TEXT);
document.Add(new Paragraph(ph)); 

In this case, I add Times Roman to the font selector first, following by MSung-Light. Now all the English characters in TEXT will be in Times Roman. The characters you say are missing will be rendered using MSung-Light. If you change the order of MSung-Light and Times Roman, the complete TEXT will be rendered in MSung-Light, so make sure you choose your fonts wisely. The order matters, and every character in your TEXT for which you didn't define a font will be missing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...