henriqueor henriqueor - 5 months ago 6
Java Question

Jasper Reports font size always 10 when exported

I'm trying to use different font sizes in my reports. Inside the Jaspersoft Studio it shows text with the correct font size, but when I export to PDF using my Java software, it gets font size 10 for the entire report.

I have tried many different fonts, but I get the same output.
I'm using jasperreports-5.6.1.

I included the following jars to the classpath.:


  • jasperreports-5.6.1.jar

  • jasperreports-chart-theme-5.6.1.jar

  • jasperreports-fonts-5.6.1.jar

  • jasperreports-functions-5.6.1.jar



I tried to export to Html using my Java program, and it didnĀ“t work. It assumes font size 10 on any exported format. I tried to use many font sizes.

this is my jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 5.6.2.final using JasperReports Library version 5.6.1 -->
<!-- 2015-09-29T14:58:11 -->
<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="fnc_venda_delivery_por_cliente_detalhado" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="1da45d48-333d-4496-ba82-e39cc4ea3ae7">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<parameter name="dataInicial" class="java.util.Date"/>
<parameter name="dataFinal" class="java.util.Date"/>
<parameter name="nomeSistema" class="java.lang.String"/>
<parameter name="nomeRelatorio" class="java.lang.String"/>
<parameter name="nomeEmpresa" class="java.lang.String"/>
<parameter name="nomeUsuario" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="vendaData" class="java.util.Date"/>
<field name="numeroDocumentoVenda" class="java.lang.String"/>
<field name="numeroSerieSat" class="java.lang.String"/>
<field name="empresaDescricao" class="java.lang.String"/>
<field name="terminalPdv.descricao" class="java.lang.String"/>
<field name="parcelaNumero" class="java.lang.Integer"/>
<field name="parcelaValor" class="java.math.BigDecimal"/>
<field name="pagamentoData" class="java.util.Date"/>
<field name="pagamentoValor" class="java.math.BigDecimal"/>
<field name="pagamentoJuros" class="java.math.BigDecimal"/>
<field name="pagamentoDesconto" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</band>
</title>
<pageHeader>
<band splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</band>
</pageHeader>
<columnHeader>
<band height="15" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<staticText>
<reportElement x="1" y="0" width="54" height="15" uuid="fd3d2c8d-07ef-4cfd-a62d-7b2fbe9f4dca">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Data Venda]]></text>
</staticText>
<staticText>
<reportElement x="58" y="0" width="30" height="15" uuid="1a2e14de-be90-4a0c-8b44-dff30061a059"/>
<textElement>
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Cupom]]></text>
</staticText>
<staticText>
<reportElement x="110" y="0" width="44" height="15" uuid="f6f31d52-0b69-47f2-8eeb-d7585d45d514"/>
<textElement>
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[SAT]]></text>
</staticText>
<staticText>
<reportElement x="263" y="0" width="58" height="15" uuid="126d1c6d-ae28-4538-9fb2-5b65c45bcf5c"/>
<textElement>
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Terminal]]></text>
</staticText>
<staticText>
<reportElement x="370" y="0" width="40" height="15" uuid="cf4976c9-a1b8-4b7b-9369-6996da1b990b"/>
<textElement>
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Data Pgto]]></text>
</staticText>
<staticText>
<reportElement x="325" y="0" width="42" height="15" uuid="30add7e7-08ea-45f0-8c28-a19cc225df1f"/>
<textElement textAlignment="Right">
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Valor]]></text>
</staticText>
<staticText>
<reportElement x="90" y="0" width="15" height="15" uuid="c0c6fbdf-f881-4c6d-936b-e40929549143">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Left">
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[P]]></text>
</staticText>
<staticText>
<reportElement x="155" y="0" width="70" height="15" uuid="526bf8cc-9aea-4cb4-b719-4c12c764c87e"/>
<textElement>
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Empresa]]></text>
</staticText>
<staticText>
<reportElement x="410" y="0" width="59" height="15" uuid="e2b262ed-bb0a-454a-b601-76e796b2601e"/>
<textElement textAlignment="Right">
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Valor Pgto]]></text>
</staticText>
<staticText>
<reportElement x="472" y="0" width="40" height="15" uuid="e1ab4731-fcb3-4b0c-858e-6e536125bdda"/>
<textElement textAlignment="Right">
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Juros]]></text>
</staticText>
<staticText>
<reportElement x="515" y="0" width="40" height="15" uuid="a14801b3-e7c7-4e87-a700-d1d877ffef55"/>
<textElement textAlignment="Right">
<font fontName="UbuntuMonoFont" size="7" isBold="true"/>
</textElement>
<text><![CDATA[Desconto]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="31" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField pattern="dd/MM/yy HH:mm" isBlankWhenNull="true">
<reportElement style="TesteFont6" x="1" y="1" width="55" height="30" uuid="fe73298a-11e2-458b-ba1f-a50d3cbc2dc8">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{vendaData}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement style="TesteFont6" x="58" y="1" width="30" height="30" uuid="b94362ef-8ab9-4147-8c70-1dc340afcebc">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{numeroDocumentoVenda}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement style="TesteFont6" x="110" y="1" width="43" height="30" uuid="22009fa5-77a0-4d3c-a14b-c8bdc0762eee">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{numeroSerieSat}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="263" y="1" width="59" height="30" uuid="954772cb-f737-49e0-a70c-7aa8e60337f5">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{terminalPdv.descricao}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="155" y="1" width="105" height="30" uuid="302c9609-68db-47c7-bc4d-456aa1c6da8b">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{empresaDescricao}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement style="TesteFont6" x="90" y="1" width="15" height="30" uuid="ed5d0d92-214b-4955-9198-0f2a4a49a062">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Left">
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{parcelaNumero}]]></textFieldExpression>
</textField>
<textField pattern="dd/MM/yy HH:mm" isBlankWhenNull="true">
<reportElement x="370" y="1" width="55" height="30" uuid="4b4b93d9-1b83-4f04-8d07-10ddcd10e394">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{pagamentoData}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00" isBlankWhenNull="true">
<reportElement x="325" y="1" width="42" height="30" uuid="8345515e-e50d-4820-aa56-fdfa0a789be7">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Right">
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{parcelaValor}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00" isBlankWhenNull="true">
<reportElement x="429" y="1" width="40" height="30" uuid="b07508eb-be76-44ec-b14a-5cc93d09358f">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Right">
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{pagamentoValor}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00" isBlankWhenNull="true">
<reportElement x="472" y="1" width="40" height="30" uuid="eb747941-b01d-4c15-8ab8-61765c15cd37">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Right">
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{pagamentoJuros}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00" isBlankWhenNull="true">
<reportElement x="515" y="1" width="40" height="30" uuid="5c195c3d-8bbe-4f96-8a6c-7f891339a508">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Right">
<font fontName="Times New Roman" size="6"/>
</textElement>
<textFieldExpression><![CDATA[$F{pagamentoDesconto}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</band>
</columnFooter>
<pageFooter>
<band splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</band>
</pageFooter>
<summary>
<band splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</band>
</summary>



Answer

I found on Google this post : http://community.jaspersoft.com/questions/826303/font-size-tomcat-pdf-generation

It solved my problem, but I don't like the ideia of compiling my reports inside my application. The Jaspersoft Studio should compile it the right way.

I have to compile my jxml file inside my java program to generate the .jasper file, before filling the report:

String jrxmlFile = "\path\to\file\report.jrxml";
String jasperDestination = "\path\to\file\report.jasper";
JasperCompileManager.compileReportToFile(jrxmlFile, jasperDestination);

If someone solved this issue without having to compile the jrxml inside java code, please let me know, I'll mark as the correct answer then.