2005 IR Help Posted August 27, 2006 Share Posted August 27, 2006 By: Brett Sutton - sbrettsutton FAQ: using fonts and barcodes in iReports/Jas 2004-08-24 03:27 I have spent a considerable amount of time over the last two or three weeks trying to work out how fonts work in iReport/Jasper. The following is a summary of what I've learnt. Given the difficulty that I had in gleaning this information I thought it might be useful to post a summary here. It would be really nice if someone with access would consider posting this as a permenant FAQ entry (if we had a FAQ). How do I use Fonts/barcodes with JasperReports/iReports Firstly you need to understand that Jasper/iReports uses two font systems, one for PDF files and one for everything else. If you open the properties dialog for any field or static text element iReports displays FOUR font droplist: Report font Font name PDF font name TrueType font Report font When you first install iReport the 'Report font' droplist is empty. The Report font option allows you to define a common set of fonts that you regularly use, including the ability to set a default font which is used whenever you add a new field to a report. Think of report fonts as dumb style sheets. They simply allow you to create an alias for an existing font. To define a 'Report font' click the 'View' menu and then 'Report fonts'. Font name This is the standard way of setting a font for a field or text element. This list will be filled with all of the standard system fonts. You can extend this list by adding additional directories which contain fonts to your java classpath. (I suspect that you could also add a jar which contained font files to your classpath but I haven't tried it). Note if you expect your report to execute with non-system fonts then you must also include the font directory on you class path at runtime. (e.g. For a servlet container just drop the font in the classes directory or add its directory to the servlet engines classpath). Barcodes No special handling is require for barcodes, the only trick is that you need to ensure that they are either a system font or that they are on your java classpath. PDF Font Name If you intending renderint PDF files from your JasperReport then you need to set the PDF Font Name. When generating PDF files JasperReports ignores the 'Font name' setting described above and uses the 'PDF Font Name' instead. I'm a little uncertain where iReports gets the list of font name for this droplist (you may have noticed that the list is different from that found in the 'Font name' droplist). I suspect that the PDF format defines a list of 'well-known' fonts which are automatically supported by the PDF format and that this list is based on that 'well-known' list. It is worth highlighting the fact that both JasperReports and iReports ignore system fonts when it comes to rendering PDF files. In both cases you need to explicitly add the system fonts to your classpath if you whish to use system fonts when designing reports with iReport or rendering reports with JasperReports. Barcodes To use barcodes with Jasper/iReports to render PDF's you need to use the 'True Type Font' option described below and ensure that they are on your java classpath. True Type Fonts The 'True Type Fonts' droplist only applies to PDF generation. The True Type Font allows you to render reports to PDF format using non-standard fonts (i.e. fonts no on the 'well-known' list). As the name suggests only true type fonts are supported. To use 'True Type Fonts' you need to do the following: Add the location of the desired fonts to the java classpath Select the 'External TTF Font...' option from the 'PDF Font Name' droplist. Select the font from the 'Trye Type fonts' droplist. Note system fonts don't appear in this droplist unless you explicitly include them on your java classpathPost edited by: 2004 JR Help, at: 2006/08/26 17:05 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now