Here is my working sample.
The font definition file (I dig it from the font’s jar file):
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="Arial">
<normal><![CDATA[fonts/arial.ttf]]></normal>
<bold><![CDATA[fonts/arialbd.ttf]]></bold>
<italic><![CDATA[fonts/ariali.ttf]]></italic>
<boldItalic><![CDATA[fonts/arialbi.ttf]]></boldItalic>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[false]]></pdfEmbedded>
</fontFamily>
</fontFamilies>
The jar file is in the application’s classpath.
And here is my java code:
String defaultPDFFont = "Arial";
JRProperties.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
JRProperties.setProperty("net.sf.jasperreports.default.font.name", defaultPDFFont);
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params);
JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName);
I set the net.sf.jasperreports.awt.ignore.missing.font
property to prevent the error you have (JRFontNotFoundException: Font 'Arial Custom' is not available to the JVM exception
) in case the font is missing. And I set the net.sf.jasperreports.default.font.name
property for determine the font that will be used in the resulting pdf file.
You can read info about this properties: net.sf.jasperreports.awt.ignore.missing.font and net.sf.jasperreports.default.font.name.
The resulting pdf file is using this font (Arial
in this sample).