views:

304

answers:

1

Hi. I have a problem with with unicode characters in generated pdf. Everything works fine on my own workstation, but at 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)
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.

+1  A: 

I doubt that the problem is related to iText. Are you sure that unit.getName() is returning the correct string?

Could it be that the unit names are e.g. read from a configuration file using the VM's default character encoding and that it matches the file encoding on your system, but is incorrect in the test environment (file is UTF-8 encoded, but test system runs with ISO-8859-1 or Cp1252 encoding)?


Ok, second guess: You write that your Java source files are UTF-8 encoded. Are you sure that you tell the Java compiler to use UTF-8 encoding for the source files when you build for the test environment?

jarnbjo
Unit name getters are dead simple, they just return a hard coded string. In this case body is `return "°C";`. So no resource file loading applies here.
Ahe
Thanks, It gave me few ideas to test but no :(. Build is done on my machine with maven (only with different db-profile). You are right in that this has probably nothing to do with iText. Simple pdf-test-program produced identical output on both systems so the problem is elsewhere and has nothing to do with a code but rather environment. I mark this correct because problem is probably so specific that giving enough information is nearly impossible. I'll be sure to report to this thread when this gets solved.
Ahe