2
votes

I'm working with academic app with 2 parts, server and client...

On client side, the user uses forms to interact (CRUD) and call report requests to server (reports like a Day sales).

The client app sends a RMI request to server app and server return a JasperPrint object across RMI request (response) to this client.

One time in client app, this JasperPrint will be appended on JFrame an showed to user.

...OK...

Today i needed create an new report, that this report uses an particular font (like certificates font) and i've installed this font on JVM server machine (/usr/lib/jvm/jdk-1.7.0/jre/lib/fonts/) only...on client not.

When client user call this report, the client app throws a jasper font not found exception...referencing this font.

I believe that JasperPrint when appended on JFrame try use client available fonts..just this font.

The question is: How i can to client doesn't need this font installed to view this report, AND, i'm not convert the JasperPrint views to PDF views in all my app ?

A sample code of FacadeRMI call:

ReportsManager rm = FacadeFactoryLocal.newInstance(ReportsManager.class);
JasperPrint jasperPrint = rm.geraRelatorio(reportFile, parameters);

// ...
JFrame viewer = new JFrame("Report content");
viewer.setPreferredSize(new Dimension(800, 600));
viewer.setLocationRelativeTo(null);

JasperViewer jrViewer = new JasperViewer(print, true);
viewer.getContentPane().add(jrViewer.getContentPane());
new FrameConfig(viewer); // show the frame with validations.

Best regards.

1
You can try to use net.sf.jasperreports.awt.ignore.missing.font property for ignoring JRFontNotFoundException exception.Alex K
You can look at JVM fonts and JasperReports postAlex K
Hi Alex, thanks for your reply. but i've installed fonts on server JVM, but not on client side, just because this app have +- 4.000 users :/ on Linux/Mac/Windows stations....Yesterday i had have update app server and client (client by JNLP...) and i've packed this font in a jar file and added to client app classpath. 'Per hour' works fine for me, but i don't like of this way. Now, my question is: It's correct pack fonts on jar file (like Jasper Extension) and add to client app classpath ?Carlos Spohr
I think yes, it would be correct. You can pack fonts with help of iReport - using Font Extensions mechanismAlex K
Alex, see the final solution on question answer below ;)Carlos Spohr

1 Answers

1
votes

I found a solution for this problem. Yesterday i packed the mentioned font in a jar file using Jasper Font Extension XML, describing the font properties. This jar was add to client app classpath and JasperPrint renders normally the respective report in clients without required font installed on them machines.

Talking with main architect here, this solution can use used because the final jar has a small size and don't affects visual or any app's logics.

Based on Jasper specification, I created a simple Java project on Eclipse with this structure:

project-fonts/
src/
diploma.ttf
Arial Narrow.ttf
irfonts.xml
jasperreports_extension.properties

The irfonts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
    <fontFamily name="Diploma">
        <normal><![CDATA[diploma.ttf]]></normal>
        <bold><![CDATA[diploma.ttf]]></bold>
        <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
    </fontFamily>

    <fontFamily name="Arial Narrow">
        <normal><![CDATA[Arial Narrow.ttf]]></normal>
        <bold><![CDATA[Arial Narrow.ttf]]></bold>
        <boldItalic><![CDATA[Arial Narrow.ttf]]></boldItalic>
        <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
    </fontFamily>
</fontFamilies>

The jasperreports_extension.properties:

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory net.sf.jasperreports.extension.simple.font.families.ireport=irfonts.xml

To pack this project to jar file, I used Eclipse, after add this jar to client app buildpath.

Reference (courtesy of Alex)

http://jasperreports.sourceforge.net/sample.reference/fonts/index.html#fontextensions

Thanks for support, have a nice day.