JasperReports gives the possibility to use custom fonts (like true type fonts) and also embed them to the resulting pdf report. DynamicJasper also allows this feature.
| Test | Description |
| ar.com.fdvs.dj.test.FontReportTest | Shows how to create reports using custtom fonts |
The code example
Font font = new Font(28,"Colonna MT","/fonts/COLONNA.TTF",Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing,true); Style titleStyle = new StyleBuilder(false).setFont(font).build();
The constructor of the Font class has the parameters for embedding the font
public Font(int fontSize, String fontName, String pdfFontName, String pdfFontEncoding, boolean pdfFontEmbedded)
Where
Note that the ttf file must be in the classpath
1.- If the ttf is not installed in your system (e.g. Windows), you will not see in the preview screen the font. Just copy the desired ttf to Windows fonts folder and run again the report.
2.- If you embed the font into the PDF, it doesn't matter if you don't see it in the previewer, the final pdf will be OK.