Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
646 views
in Technique[技术] by (71.8m points)

jasper reports - Indentation in generated PDF using JasperReports

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...