Jasper reports font size issue exporting to pdf

Paco Abato picture Paco Abato · May 29, 2014 · Viewed 11.5k times · Source

I'm using Jaspersoft Studio 5.6.

It displays correctly in Jaspersoft Studio in Design view. In Preview view it is also correctly displayed (using java or pdf).
When I execute the report from my Java application the three texts are displayed at the same size.

I noticed that Bold and Italic works fine but if I change the font (DejaVu, Arial, Times new roman, etc) that is also ignored. In the report generated by my application I always get the same font.

What is failing? Am I forgetting any configuration option?

The example mixes static fields and text fields just to test.

EDIT:

It seems like I found a "solution" (wich has side effects).

I was generating the report like this:

JasperRunManager.runReportToPdfStream(stream, outStream, params, datasource);

Now, generating in this way the size of the texts are correct in the generated pdf:

JasperReport jasperReport = JasperCompileManager.compileReport("my/report.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, datasource);
JasperExportManager.exportReportToPdfStream(jasperPrint, outStream);

The font type however is not correct.

The side effect, I think, is that JasperRunManager.runReportToPdfStream does not load the report into memory while JasperFillManager.fillReport does.

Any idea about why JasperRunManager.runReportToPdfStream ignores the font size?

Any idea about why the other way is ignoring the font type? Both JSS and my java application are on the same Windows machine (so the fonts must be available to both).

Any advise to avoid loading into memory the whole report?

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="subinforme_pag_1" pageWidth="802" pageHeight="552" orientation="Landscape" columnWidth="802" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="c6f5d08f-f28b-4c77-8523-5cf4746cdcf2">
    <queryString language="SQL">
        <![CDATA[]]>
    </queryString>
    <detail>
        <band height="551" splitType="Stretch">
            <textField>
                <reportElement x="0" y="80" width="180" height="40" uuid="50721cba-c082-47de-9abf-effcf1b784dd">
                    <property name="local_mesure_unitheight" value="pixel"/>
                </reportElement>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="4"/>
                </textElement>
                <textFieldExpression><![CDATA["Text Field (size 4)"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="0" width="180" height="40" uuid="05c5129f-f29e-47a1-ad82-4547b51e3d56"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="16"/>
                </textElement>
                <textFieldExpression><![CDATA["Text Field (Size 16)"]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="40" width="180" height="40" uuid="5c69d29b-b168-408d-89aa-c6d527f0cae1">
                    <property name="local_mesure_unitwidth" value="pixel"/>
                    <printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
                </reportElement>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="8" isBold="false"/>
                </textElement>
                <text><![CDATA[Static Text (Size 8)]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>

Answer

Pablo picture Pablo · Apr 7, 2015

The problem is when compiled with version 5.6.0.

This is solved by compiling with the version 5.5.1

I hope they fix the issue!