Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasper text field getting truncated

I'm having a font issue with my jasper report where one of my more wordy text fields (the last one in a detail band) is getting cut off in the PDF and PDF Preview but not in the Internal Preview.

e.g.

Internal Preview:

Here is a fake description. It fits
perfectly, fitting just in the lines.

PDF Preview

Here is a fake description. It 
fits perfectly, fitting just in the

Jasper is (seemingly) using some algorithm to figure out how tall the field should be, my text is barely fitting, then when the PDF is generated the text wraps and disappears on the next line.

I'm not using custom fonts (just the default/implicit "SansSerif"), and not using any custom styles beyond bold/italic. This behavior is demonstrable in both iReport's PDF Preview and my code's generated PDF on Windows and MacOS (Linux likely still has the issue, but my example text didn't exhibit the behavior on Ubuntu).

I've played with Stretch Type, Position Type, and Stretch with Overflow, as well as moved this text field to its own band but none fixes this bug (and several of them cause others).

I've had luck changing the font to the other built-in fonts, but this just tells me my example doesn't work for that particular font, not that I've fixed the bug.

Any tips would be greatly appreciated.

Update 1

I tried upgrading from Jasper Reports 5.2.0 to 6.2.0 and Jasper Fonts 4.0.0 to 6.0.0... no change.

Update 2

Tried editing my src/main/resources/jasperreports_extension.properties and adding

net.sf.jasperreports.export.pdf.force.linebreak.policy=true

... no change.

(Notably though in my use-case I can't use isStretchWithOverflow="true", so this may be why it didn't work.)

Update 3

I tried embedding the font by editing src/main/resources/jasperreports_extension.xml and adding:

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.arialFontFamily=fonts/customFontFamilies.xml

customFontFamilies.xml:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
 <fontFamily name="ArialEM">
   <normal><![CDATA[fonts/Arial/Arial.ttf]]></normal>
   <bold><![CDATA[fonts/Arial/Arial Bold.ttf]]></bold>
   <italic><![CDATA[fonts/Arial/Arial Italic.ttf]]></italic>
   <boldItalic><![CDATA[fonts/Arial/Arial Bold Italic.ttf]]>/boldItalic>
   <pdfEncoding><![CDATA[Cp1252]]></pdfEncoding>
   <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
 </fontFamily>
</fontFamilies>

... no dice. (Though this did help with an issue where Firefox's PDF renderer wouldn't render bold fonts.)

Update 4

I noticed that in all the test-cases I was able to create that the first line was blank, so I changed the particular cell to be vertical-align top, which worked, but of course made that one cell misalign when there wasn't much text in it.

Scrapped that as a solution, but may work for someone.

Update 5

At this point hopefully it's clear I've tried the "real" solutions and watched them all die a horrible death. Thus, we enter the realm of the hack solution. First I tried @wmmci's solution, but his answer changes the height of my box (due to it being dynamically calculated by Dynamic Jasper). I noticed that all of the examples I could create involved intra-word periods in the string, e.g. "foo...bar". That might not be your case, but it was for me. So I injected a "hair space" (&#8202;) after intra-word spaces.

This is obviously not a real solution, just a temporary work-around until I'm able to find more examples of the bug.

Update 6

I checked and I don't have @KarolisŠarapnickis's issue with the printOrder. Ah well. I shall soldier on. ;-)

like image 541
inanutshellus Avatar asked Nov 21 '13 15:11

inanutshellus


People also ask

How do I align text in Jasper report?

Select the text filed, select "Properties" tab and select center icon in the "Text Alignment". Vote up!


2 Answers

I had same issue and I tried all possible configurations - didn't work. Finally as a workaround I appended a new line character to the field and it worked. Something like this: $F{description} + "\n"

like image 102
wmmcii Avatar answered Sep 21 '22 00:09

wmmcii


Had the same issues with text being truncated and nothing seemed to work. luckily I found out that my root xml element had the following attribute:

printOrder="Horizontal"

Removing it solved my issues.

like image 26
Karolis Šarapnickis Avatar answered Sep 19 '22 00:09

Karolis Šarapnickis