I am using jasper report for generating my PDF report. I use following textField configuration in jrxml file.
The sample PDF uses the font Helvetica (supplied by the PDF viewer) which surely is not used by JasperReports when generically pre-compiling the Report.
If different fonts (having different font metrics) are used like this, fields in the output may turn out to be too big or too small. Thus, I'd advice to explicitly set the font, and to do so using both the fontName
and the pdfFontName
attributes indicating the same TTF font. Alternatively this can be done more cleanly using JasperReports font extensions. Cf. JasperReports - Fonts Sample for details.
fontName
and pdfFontName
E.g., assuming that you are working in a Windows environment and have the appropriate permissions (otherwise simply adapt the path to point to your copy of the font), you can use Arial like this:
PDF is a special case in JasperReports because in contrast to most other output formats (which use the system fonts) PDF viewers foremost use one of the standard 14 fonts every PDF viewer must supply or fonts embedded in the respective PDF document; therefore, PDF file generation differs a bit.
The cleaner approach requires you to write a file defining your font families with all relevant information, e.g.
admin/plugins/ireport/config/fonts/verdana.ttf
admin/plugins/ireport/config/fonts/verdanab.ttf
admin/plugins/ireport/config/fonts/verdanai.ttf
admin/plugins/ireport/config/fonts/verdanaz.ttf
Identity-H
true
(The fonts referenced from that file (verdana*.ttf) are part of the Microsoft "TrueType core fonts for the Web" collection. The license agreement for their use can be found in eula.html which can currently (as of 2011-04-01) be found at http://www.microsoft.com/typography/fontpack/eula.htm.)
Then you need to tell JasperReports font extensions to retrieve its information from that file as described in the JasperReports font extension sample, i.e. by providing a jasperreports_extension.properties
file in the root package containing
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.dejavu=my_path/fonts.xml
(the pointed-to fonts.xml is the file mentioned above.)