[#12071] - Using linespacing on TextField looses the last line of text when stretched

Bug report
Project: Severity:
No Change Required
Component: Reproducibility:
Assigned to:

Jasper seems to use some sort of calculated line spacing which gives to much white area when text need to be compressed to save paper as well fitting as much text as possible in a frame.

Configuring linespacing attribute to Proportional and a value of 0.5 looses the last line when the element is stretched hence legal information and so forth are lost and not displayed. See attached image when previewed in Jaspersoft Studio where you see that java generates the text correctly, while using the PDF previewer looses the last line.

I have tested this with some different versions of jasper (6.6, 6.7, 6.8, 6.9) and even the AGPL version (jasperreports-pdf-lib5), and they all looses the last line when exporting to a PDF.

Here is a sample JRXML file which could be used to reproduce the problem:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="7941b5f6-2c9c-458e-ad67-c4b6d9d066ff">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<band height="30" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="201" height="30" uuid="e82b3889-2328-49e8-a2e9-ab068348640f"/>
<font fontName="Arial" size="12"/>
<paragraph lineSpacing="Proportional" lineSpacingSize="0.5"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas et tortor at lorem malesuada mollis. In hac habitasse platea dictumst. Vestibulum laoreet ultrices libero sed tristique. Sed vulputate velit sed sem suscipit, at rutrum diam accumsan. Proin maximus ante sed mattis pellentesque. Etiam dapibus et ante fermentum tincidunt. Maecenas imperdiet quis nunc in maximus. Lorem ipsum"]]></textFieldExpression>

Image icon missing-last-line.png419.14 KB
jasper library
T3O's picture
Joined: Aug 14 2019 - 6:34am
Last seen: 5 months 2 days ago


  • Status:New» Feedback Requested
  • Assigned:nobody» teodord


There are two issues in this case:

#1 Are you sure the Arial font is installed on the Mac machine where you run JSS (judging from the screenshot).
For pixel-perfect output, you need to make sure the fonts you use in the report are available on the machine that generates the report and in addition to that, they are embedded in the PDF.
I have modified your example to use "DejaVu Sans" instead of "Arial", because this is one of the fonts that are shipped with JSS as JR font extension and is configured for PDF embedding.

#2 Add a tab character at the end of your long text (escaped as \t). This would cause the PDF exporter to use a more precise text renderer, which is also a little bit slower due to its higher precision.
By default, we use a simpler/faster PDF text renderer which has a very small line spacing difference compared to AWT, which gets exacerbated over multiple lines of text, eventually throwing the last line out of bounds.
The presence of a tab character in the text triggers the use of the more precise renderer, but we could add a custom property to control this without adding useless tab characters.




For better precision at #2, instead of adding a tag character to the text, which is more intrusive, you could also use a 1px indent as either first line indent, left indent or right ident for your text element.
I think 1px right ident for a left aligned text element is the less intrusive thing and it will cause the PDF exporter to use the more precise text renderer making it look exactly like in AWT.

Feel free to reopen this if you still have the problem.

Thank you,

  • Resolution:Open» No Change Required
  • Status:Feedback Requested» Resolved

Sorry for the late response. I used \t which resolved this issue among others with overlapping text and so forth. Thanks for the tip with the 1px indent, will keep that in mind if I see any problems with the \t.