views:

1068

answers:

7

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.

+5  A: 

OpenJDK has to put out fonts which are copyright protected. Install Sun's Java and fonts will be somehwat better.

ante.sabo
Good suggestion. I'll try, thanks.
mooware
It worked! I also installed a package named "Ubuntu restricted extras", which made the fonts in OpenJDK a bit better, but Sun's JRE renders them much better.
mooware
+1  A: 

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.

Sam DeFabbia-Kane
I don't think I could change the font easily, since it's defined in the PDF document, but the font hinting sounds like a good idea.
mooware
+1  A: 

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.

jwaddell
A: 

u can try copy all your windows fonts, and put them into your linux environment.

janetsmith
A: 

Are the fonts embedded in the PDF?

mark stephens
I think the garbled fonts are not embedded. AFAIK the PDF standard defines a few standard fonts which will not be embedded.
mooware
Looks like I was wrong. The garbled fonts can be embedded ones.
mooware
Embedded fonts have alsorts of potential issues with Java such as encoding and patent issues. It is down how the renderer handles these....
mark stephens
+1  A: 

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)?

mark stephens
I'm using JPedal in my project and also tested it with the IcePDF Webstart Demo and the Swinglabs PDFRenderer. They had the same issues. The problem was OpenJDK. I installed Sun JRE and everything worked fine.
mooware
A: 

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.

somegirl