Many people may not care about unicode when using JasperReports. They just choose the font they like for their fields and static text, run the report and that´s it. But if your report contains characters, which are not contained in your default non unicode operating system characterset, you'll be surprised. You`ll get correct print preview and printout but no correct pdf export. Some characters will miss.
I had this problem and what I found on the internet was quite confusing. I found everythig from "this is a bug in the underlaying itext library" to complicated looking solutions using deprecated JasperReports functions.
But the real solution is fortunately quite simple...
Just switch the font name of the desired field to "DejaVu Sans". Depending on the used characters you may notice that they are now visible in pdf too.
(The DejaVu font family is a bit limited but for example you will be able to export cyrillic characters with it. See http://dejavu-fonts.org for further information.)
You switched the font name property of the desired field to "DejaVu Sans" and you checked on the website that the characters are included in the font but you still got nothing in your PDF?
Did you previously play with the deprecated options like "PDF Font name" or "PDF Encoding"? Even if you switch back this options to their default values this may be the reason that you don't get it displayed in PDF. You have to switch to the xml view of your report definition and check that these options are NOT present at all!
For example this does not work:
<staticText> <reportElement x="14" y="63" width="521" height="24"/> <textElement> <font fontName="DejaVu Sans" size="15" pdfFontName="DejaVu Sans" pdfEncoding="Identity-H"/> </textElement> <text><![CDATA[Cyrillic: б в г д ж з и ь к л м н п ф ц ч ш шт э я ю я ы]]></text> </staticText>
This will work as the pdfFontName and pdfEncoding attributes are not present:
<staticText> <reportElement x="14" y="63" width="521" height="24"/> <textElement> <font fontName="DejaVu Sans" size="15"/> </textElement> <text><![CDATA[Cyrillic: б в г д ж з и ь к л м н п ф ц ч ш шт э я ю я ы]]></text> </staticText>
Maybe your characters are not displayed with the DejaVu fonts or you just don't like this font. What about using Arial or any other unicode font?
To achieve this you must provide your font in a special way to JasperReports. This means your fonts must be put in a .jar file which must contain additional information in a property file and a special xml file describing the contained fonts. This jar file must be on the java classpath while you execute your report. Sounds complicated? Don't panic... ;-)
You can create such a font jar file in two steps using the graphical report editor iReport which you may already be using.
If you open the selection list of the font name property in iReports, you may notice that there are a few entries at the top of the list and then, devided by a dash, a longer list of fonts. The longer list beneath the dash are the fonts installed in your operating system whilest the entries above are fonts that are installed into iReports. Only these installed fonts can be used to export unicode characters to pdf whithin iReports. So the first step is to install your favorite font to iReport.
You now see a list of all already installed fonts. The three DejaVue fonts are installed by default and the other three are generic font aliases.
Now you shoud be able to export your report to pdf from within iReport using your installed font and foreign characters.
A note to Windows 7 users:
You may get an error if you try to install a font into iReport because you have no right to write into the directory. Change the security property of the
C:\Program Files\Jaspersoft\iReport-4.1.1\ireport\fonts
or
C:\Program Files (x86)\Jaspersoft\iReport-4.1.1\ireport\fonts
directory to allow users to write there.
Now you have a ready to use font jar which can be used with JasperReports. Just add it to the classpath of your application.