6

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 Example text field in PDF report

iReport Designer Preview Example text field in iReport Designer

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":

PDF report (stretchWithOverflow true)

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

Cornelia
  • 63
  • 1
  • 6
  • I posted an answer, if you still have problem post the relevant jrxml code and code you use to export to pdf. – Petter Friberg Dec 14 '15 at 16:56
  • Thank you for your answer @Petter. I will have another look at it tomorrow in the office. I still don't really understand why there's an empty space in the textField (the whole blue box is the textField) but I'll try to wrap my head around it! – Cornelia Dec 14 '15 at 20:41
  • Pass the jrxml relative to the textField and the blueband..., When calculating how and if it is necessary to wrap, FontMetrics is used, I would guess (if its true that whole blue band is textfield, with no padding), that there is a problem calculating the FontMetrics... – Petter Friberg Dec 15 '15 at 08:06
  • My feeling is still that you have a problem with font in pdf, can't see the style "Unicode", if you post it its better, but I can see isBold="true", so maybe jasper calculates your FontMetrics on one font (bold), but iText display's it with another (not bold?)....I strongly recommend you add the font-extension before exporting to pdf (this is good practice in any case) and then check what your result is. – Petter Friberg Dec 15 '15 at 10:27
  • 1
    @Petter: I finally figured it out. Font extensions were already enabled, but the Style for "Unicode" stated `isBold="false"`and the textElement had `isBold="true"`. I deleted the true in the textElement after noticing the font is not displayed as bold in the invoice anyway and now everything is displayed fine. So iText probably displayed it normal but calculated as bold. Thanks for all your help! – Cornelia Dec 16 '15 at 09:05

1 Answers1

4

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"

Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • Hi Petter, thanks for your reply! I edited my question to add the code for the textField (I'm not allowed to post more) and a screenshot of what happens with `isStretchWithOverflow="true"`. Maybe you have further suggestions. – Cornelia Dec 15 '15 at 09:37
  • @Cornelia It would be better if you also post your style definition "Unicode", have you tried adding font extensions.. – Petter Friberg Dec 15 '15 at 10:18