开发者

Using unicode character in generated PDF using iText5

I have a problem with with unicode characters in a generated PDF. Everything works fine on my own workstation, but on the test environment things go wrong.

Code inserting value is following:

Font boldDefaultFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD);
// ...
PdfPCell headerCell = new PdfPCell();
// unit.getName() returns "°C"
Phrase header =  new Phrase(unit.getName(), boldDefaultFont);
headerCell.addElement(header);

Java source code is in UTF-8.

When this is run in my environment (java 1.6.0_18, WinXP) cell contains °C as I would expect, but in test-environment (java 1.6.0_18, Win2003) result is °C. I've figured out that this is a encoding-problem (UTF-8 '°' is 0xc2b0 which equals '°' in iso-8859-1).

For now I've tried following:

1) adding -Dfile.encoding=utf8 to java options (no effect in either environment)

2) adding ARIALUNI.TTF to test environments C:\WINDOWS\Fonts (no effect)

开发者_JAVA技巧3) encoding unit.getName() to iso-8859-1, but it made the degree sing disappear in my machine.

Environment that views the pdf has no effect, pdf generated on my workstation shows nicely everywhere and vice versa.

Does anyone have experience on this subject? I bet there is a way to get this working in both environments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜