I'm writing a java application that renders PDF documents to images, and when I run it on windows it works fine. But when I render the PDF on Linux, the standard fonts look a bit garbled, like there would be a few pixels missing on the right side of some characters.
I only tested it on a fresh install of Ubuntu 9.04 with OpenJDK 6, but I'm quite sure I have seen similar issues before on Linux. I also tried to open the PDF with other Java PDF applications, like the SwingLabs PDFRenderer and the IcePDF Demo Applet, and they had the same problem. On windows they all render the document just fine. I also opened the document on the same Ubuntu machine with the default PDF viewer, evince. Evince rendered the document without the font issue, so I'm quite sure this is a general Java + Linux problem.
For comparison:
This image was rendered on Windows.
This image was rendered on Linux. I marked a few garbled characters with red rings.
This one was also rendered on Linux. It looks like only standard fonts are affected.
Any help is appreciated.
OpenJDK has to put out fonts which are copyright protected. Install Sun's Java and fonts will be somehwat better.
I have OpenJDK installed in Linux and all apps were with very, very bad fonts... after many tries to change fonts, antialias, installing Lucida fonts, etc. I found that my problem was in the /etc/fonts/conf.d/35-freefont.conf
.
I simply removed that link, run fc-cache -f
and all new Java apps got a much better font.
In my case, the freefont config was telling Java to use it instead of much better fonts. If you have a similar problem, simply run sudo mv /etc/fonts/conf.d /etc/fonts/conf.d.off
and a fc-cache -f
and test...
If it works, you also have a bad default font substitution and you should restore that dir and test each file.
If it stays the same, then you probably have another problem (don't forget to restore the conf.d
dir)
Update
On Ubuntu 12.04, I had a similar problem, all Java fonts where bold. Removing /etc/fonts/conf.d/65-nonlatin.conf
fixed the problem.
Could be font hinting gone bad. Check the font hinting settings of the Linux OS you're working with.
Could also be the font--try specifying a different one. The one you're using may simply render badly on Linux--some just do. Palatino is one I've found to be particularly bad.
You could try using pdffonts to help you analyse the problem - it would at least tell you the names of the fonts used in the PDF file, their type, if they are embedded etc. If the fonts are not embedded you could try installing them on the Linux machine.
There are 8 standard font families you do not need to embed as the PDF viewer should provide. Otherwise they will be substituted. What does the PDF look like in the other PDF Java Open Source viewers (Multivalent, JPedal)?
You can use openJDK and use Sun/Oracle's fonts!
First install openDJK (both runtime and dev packages)
Then install Sun/Oracle's runtime only. This will install the fonts, but you'll still be using openJDK's java to run everything.
Install the latest version of OpenJDK. Or recompile Freetype with hinting enabled. The Apple patents regarding hinting have expired.
Are the fonts embedded in the PDF?
Try to copy all your windows fonts, and put them into your linux environment.
I haven't test it but according to this forum post at inductiveautomation.com you can correct it by installing the fonts:
sudo apt-get install msttcorefonts
and changing lucidasans for arial in the properties of Java fonts:
sudo nano /usr/lib/jvm/java-6-sun/jre/lib/fontconfig.properties