Search code examples
jasper-reportsexport-to-pdf

Detail's text field seems to have a characters limit and stops stretching


I have four reports that are basically different formats of the same report and the following problem happens with three of them. I have a text field in the Detail's band that is marked as Stretch with Overflow. The problem is that it seems that it has some kind of characters limit, because with the following text (110 characters):

MAD.ESP.TAUARI(COURATARI GUIANENSIS AUBL.)SERRADA EM RIPA.KD.FAS.FSC 100% MED.19,1MMX38,1MMX2438,4MM DE COMP.

It's only printing:

MAD.ESP.TAUARI(COURATARI GUIANENSIS AUBL.)SERRADA EM RIPA.KD.FAS.FSC 100% MED.19,1MMX38,1MMX2438,4MM DE

As shown in the screen shots:

First report Second report Third report (only one printing correctly) Fourth report

It's woth noting that when using the "preview" of the JasperStudio, the whole text appears normally for all of them.

Here's the text field's code of one of them. They're basically the same, changing the width, height and position.

<textField isStretchWithOverflow="true">
    <reportElement x="26" y="0" width="76" height="10">
    </reportElement>
    <textElement textAlignment="Center" verticalAlignment="Top">
        <font fontName="Arial" size="8"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{descricaoProduto}]]></textFieldExpression>
</textField>

I'm using the 6.2.2 version of JasperReports.

EDIT:

I created a gist with a minimal version of the report that the problem happens:

Sample

I'm exporting it to PDF and using Arial as the font (I added a JAR with the Arial font).


Solution

  • Set the net.sf.jasperreports.export.pdf.force.linebreak.policy property to true (in jasperreports.properties or programmatically). See http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.pdf.force.linebreak.policy

    The property instructs the PDF exporter to use java.text.BreakIterator to determine where line breaks can occur in texts, which ensures that the line breaks at PDF export time match the breaks uses when the text was measured at report fill time. As a note, this might come with some impact on PDF exporting performance, but it shouldn't be dramatic.