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)
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.
精彩评论