Indentation in generated PDF using JasperReports
Asked Answered
P

1

8

I have a piece of HTML stored in a database as:

<ul>
<li>Pretend you're talking to a busy colleague and  have to sum up your   entire question in one sentence: what details can  you include that will help someone identify and solve your problem?</li>
<li>Spelling, grammar and punctuation are important!  Remember, this is the first part of your question others will see - you  want to make a good impression. If you're not comfortable writing in  English, ask a friend to proof-read it for you. </li>
<li>If you're having trouble summarizing the problem, write the title last - sometimes writing the rest of the question first can make it easier to describe the problem.&nbsp;</li>
</ul>

I am displaying this piece of HTML in a PDF using a JasperReports textField, the above HTML should display like this in the generated PDF.

  • Pretend you're talking to a busy colleague and have to sum up your entire question in one sentence: what details can you include that will help someone identify and solve your problem?
  • Spelling, grammar and punctuation are important! Remember, this is the first part of your question others will see - you want to make a good impression. If you're not comfortable writing in English, ask a friend to proof-read it for you.
  • If you're having trouble summarizing the problem, write the title last - sometimes writing the rest of the question first can make it easier to describe the problem. 

But this HTML is showing as :

enter image description here

The snippet from jrxml file:

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
    <reportElement positionType="Float" x="7" y="47" width="501" height="15" isRemoveLineWhenBlank="true"  forecolor="#283234"/>
    <textElement markup="html">
        <font size="10"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
</textField>

HTML is feeded in description variable.

Any idea how can I align text?

Poikilothermic answered 24/10, 2014 at 15:23 Comment(2)
Related How to add indentation on bullet listBladdernose
@ABC, do you have the answer?Wages
N
9

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.

Nolin answered 27/10, 2014 at 8:42 Comment(2)
If we do something maually as you suggested that means there is no significance of ul/li in jasperreports.Poikilothermic
Jasper reports can interpret html snippets along with other markup types and they get parsed to an internal structure. The result is layouted with default styles. In your case the default list style has no hanging indent and therefore needs custom styles to achieve the desired result.Nolin

© 2022 - 2024 — McMap. All rights reserved.