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.
Asked
Active
Viewed 7,999 times
3
-
Please show the relevant parts of your code. I.e. especially the code where you define the fonts you use. – mkl Feb 21 '13 at 11:26
-
I have not defined any fonts in my code. – Mohit Shah Feb 21 '13 at 11:29
-
In that case have a look at Bruno's answer. – mkl Feb 21 '13 at 11:53
-
Found another variation on this answer here - it uses the Arial Unicode font and worked better for me. https://stackoverflow.com/questions/23958538/problems-with-chinese-fonts-in-itext-pdf-on-windows-machines – Bern Jun 07 '19 at 15:52
2 Answers
5
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.

Bruno Lowagie
- 75,994
- 9
- 109
- 165
-
Thanks Bruno. I tried the solution that you gave. It worked. Thanks a lot. – Mohit Shah Feb 21 '13 at 12:22
-
If an answer solved the problem, you can accept it. That way people with the same question will recognize it as the solution. – Bruno Lowagie Feb 21 '13 at 13:06
-
@BrunoLowagie this does not work for me (I am using itext version 5.5.13). Do I need any dll for fonts or something? – Helen Araya Apr 04 '23 at 15:42
0
"SIMSUN.ttf" works for me. You can download it from the web. https://www.wfonts.com/font/simsun

Mitko Keckaroski
- 954
- 1
- 8
- 12
-
1Please don't use bitmap images to display code, use text instead. Stack overflow offers means to format code and apply syntax highlighting. Also you should show how you create that `test.font` object: problems displaying certain glyphs often are caused by incorrect font instantiation. – mkl Dec 24 '20 at 11:50