Search code examples
jasper-reports

Change report to use a different system font


I've inherited a project that uses Jaspersoft Studio 6.2.2 (a tool I know nothing about). Reports are failing because they've been deployed to a Unix server that doesn't have the "Arial" font installed. I'm trying to replace it with "Lucida Sans", a font that I know is available

I've replaced the term "Arial" with "Lucida Console" in the two *.jrxml files I have and them recompiled to *.jasper but the report is totally ignoring the new font.

<style name="Heritage" mode="Opaque" forecolor="#E5F1FA" backcolor="#18BC9C" radius="3" hTextAlign="Center" vTextAlign="Middle" fontName="Lucida Sans" fontSize="12" isBold="true">
    <conditionalStyle>
        <conditionExpression><![CDATA[!$P{project}.isHeritage()]]></conditionExpression>
        <style mode="Opaque" forecolor="#FFFFFF" backcolor="#D62C1A"/>
    </conditionalStyle>
</style>

net.sf.jasperreports.engine.util.JRFontNotFoundException: Font "Arial" is not available to the JVM.

Is there a quick way to switch the font?

I understand there're better solutions (use font extenions or just install Arial on server) but I need a quick fix.


Solution

  • add exported font file into the project's classpath.

    try with following steps,

    1. select Window > Preferences
    2. in the preferences dialog, select Jaspersoft Studio > Fonts
    3. select Add for add the new font. in this step, set the font name and browse the relevant font files (.ttf files), then you can see, new font under the "Font List"
    4. select the desired font from "Font List" and Export to .jar file. in this step. give the name for exported font (.jar) file
    5. finally exported font file (.jar) add to the project's classpath