Jasper Report truncates text before filling the wh

2020-03-21 03:16发布

问题:

I'm having a problem with my PDF report where a String in a text field is truncated before filling the text field. The amount of missing characters (5-6) would not be enough to go over the end of the textField.

I added the text.truncate.at.char property to the report element but the String is still truncated (after displaying some more characters than before).
I also checked if there are other report elements blocking the end of the text field, but there are none.
Lastly I tried a potential fix I found and added "\n" to the end of the line, but that also did not help.

In iReport Designer the whole String is displayed.

PDF report

iReport Designer Preview

Does anyone know how to make Jasper Reports use the whole space in the text field?

PS: Allowing the text to overflow to the next line is not possible due to customer wishes.
I'm using Jasper Reports 5.5.2.

Edit:

The textField is part of a detail band in a subreport. I'm not allowed to share the whole .jrxml, but this is the code for the textField:

<textField>
    <reportElement style="Unicode" mode="Opaque" x="0" y="2" width="467" height="17" forecolor="#FFFFFF" backcolor="#00007F" uuid="e810d7a4-6802-4620-af2f-4c385a9e80a6">
        <property name="net.sf.jasperreports.text.truncate.at.char" value="true"/>          
    </reportElement>
    <textElement verticalAlignment="Middle" markup="none">
        <font size="10" isBold="true"/>
    </textElement>
    <textFieldExpression><![CDATA["   More Details - "+$F{Description} + " ("+$F{Id}+")"]]></textFieldExpression>
</textField>

The description is of variable length, the Id is a GUID. In this case there should still be more than enough space in the textField to display the whole GUID.

Here is another screenshot with isStretchWithOverflow="true":

The text is now displayed completely in the first line but the textField is larger which is not accepted by the customer.

回答1:

Why is it different in pdf and iReport designer?

This is because iText (the library creating your pdf) is doing its "best effort" to render the font you have indicated in jrxml and its not good enough (it is using another font that is bigger...).

To avoid these problems you need to use font extensions and check your settings on style and textElement

Checklist to rendered font correctly in pdf

How to add font extension using iReport

OP solved as in comment:

Font extension installed, removing isBold="true" on textElement, since the style set to textElement had isBold="false"