views:

97

answers:

1

Hi,

I am trying to use a font, that is not installed on my local OS, with a jasper report. The jasper report uses in this way:
<textField>
<reportElement x="0" y="0" width="137" height="20"/>
<textElement>
<font fontName="Corbel" size="12"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{something}]]>
</textFieldExpression>
</textField>

The font named 'Corbel' was exported as a font extension (using iReport) and is contained in file (Corbel.jar), in folder, on my system. I add this extension to the classpath of the application, using a code as follows:
... ClassLoader cl = new URLClassLoader( new URL[] {new URL("file:///D:/path/to/Corbel_jar_folder/")} );
param = new HashMap();
param.put(JRParameter.REPORT_CLASS_LOADER, cl);
jasperReport = JasperCompileManager.compileReport("d:/path/to/Report_with_Corbel_font.jrxml");
jasperPrint = JasperFillManager.fillReport(jasperReport, param, new JREmptyDataSource());

After the report is filled, I export it using a JRPdfExporter. However, in the result pdf file, the element does not have the 'Corbel' font applied. I have not included the pdf exporting, because I think that the problem is somewhere with the filling. I have searched and read numerous posts and questions related to using/including fonts (i.e.font extensions) in Jasper Reports; still I am not aware of where the mistake or the problem resides. Any help would be greatly appreciated.

Thank you in advance! (sorry for the bad code indentation and I hope I have included enough details)

Best regards, Andrei

A: 

The problem was that the loading of font extensions jars is done from the thread context classloader and from the JRParameter.REPORT_CLASS_LOADER, nor the JRExporterParameter.CLASS_LOADER.
Therefore, in my case, the current (initial) thread classloader had to be saved, the we had to do something like Thread.currentThread().setContextClassLoader(cl), where 'cl' was the context of the JasperReports based application and then the thread context classloader was reverted to the original one.

The question has been answered and details are available here.

I hope this answer will help others facing similar (font) issues.

Best regards, Andrei

AndreiC