JohnChen
JohnChen

Reputation: 13

How to display Chinese characters in java web applications?

I use Itext 5 to create pdf file. I refer to https://developers.itextpdf.com/examples/itext-action-second-edition/chapter-1 and get a pdf. When I open it, Chinese characters display normally.

But I develop web applications like https://developers.itextpdf.com/examples/itext-action-second-edition/chapter-9 described. Chinese characters is blank when pdf show in browser.

My font code is

String chFontPath = "c:\fonts\xxx.ttf"; BaseFont chBaseFont = BaseFont.CreateFont(chFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font = new Font(chBaseFont, 12);

Does anybody know?

Upvotes: 0

Views: 342

Answers (1)

Rafael Palomino
Rafael Palomino

Reputation: 318

If you embed the font using an absolute path, probably the path will be broken for any webapp you develop. Use a relative path instead for any embeddable (fonts, images, etc) so you can place them in server without any trouble.

I think Bruno's answer about a relative anchor could help you to set up a relative path for your font: https://stackoverflow.com/a/27064142/4048864

Upvotes: 0

Related Questions