Jasper reports font size issue exporting to pdf
Asked Answered
H

2

7

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>
Hornbeck answered 29/5, 2014 at 13:13 Comment(5)
post your jrxml file..Clientele
Did you ever find a solution for this as I am having the same issue?Or
Found nothing by now.Hornbeck
@PacoAbato did you get any solution ?Proem
@faizi yesterday Not yet.Hornbeck
S
11

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!

Soupy answered 7/4, 2015 at 20:34 Comment(1)
This is the link to the Jaspersoft Studio 5.5.1. sourceforge.net/projects/jasperstudio/files/…Ane
P
9

I've also had this problem. What you have to do is to upgrade de jasperreport jar in your java web application. For example, if you use iReport 5.6.0 for designing your report, upgrade your jasperreport.jar to 6.2.1

Policewoman answered 28/4, 2016 at 9:27 Comment(1)
If you upgrade to latest 6.16.0 version of jasper report also it work as suggested. This is better solution compare to above one as we don't need to downgrade our jar which is vulnerable too.Oloughlin

© 2022 - 2024 — McMap. All rights reserved.