Indentation in generated PDF using JasperReports

My solution shows the plain JRXML which is the desired result independent from the tools someone is using, e.g. iReport GUI, dynamic reports or java code designing Jasper reports.

First define a style, which corrects the indentation pulling the first line some pixels to the left and pushes the whole box the same width to the right:

<style name="hanging-indentation-style">
    <box leftPadding="23"/>
    <paragraph firstLineIndent="-23"/>
</style>

Second, this style is applied to the reportElement of the textField:

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
    <reportElement style="hanging-indentation-style" positionType="Float" mode="Transparent" x="0" y="0" width="555" height="20" isRemoveLineWhenBlank="true"/>
    <textElement markup="html"/>
    <textFieldExpression class="java.lang.String"><![CDATA[$F{description}]]></textFieldExpression>
</textField>

Depending on your font size you may vary the style values to fit your needs.

I adapted input from Aligning Bullets in Jasper Reports, where dynamic reports api is used, and Jasper Report HTML bullet hanging indent, where it is shown through the GUI, which was not possible in my case using iReport Designer 4.5.1, because there is no option to apply padding directly to a textField.

Leave a Comment