Indented PDF Generated Using JasperReports

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

<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 HTML snippet in PDF format using the JasperReports text box, the above HTML should be displayed in this way in the generated PDF file.

  • Imagine that you are talking with a busy colleague and should summarize your whole 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 that this is the first part of your question that others will see - you want to make a good impression. If you do not like writing in English, ask a friend to confirm this for you.
  • If you have problems summarizing the problem, write the title last - sometimes writing down the rest of the question first, you can easily describe the problem.
But this HTML is displayed as:

enter image description here

jrxml:

 <textField isStretchWithOverflow="true" isBlankWhenNull="true"> <reportElement uuid="9206a8ee-5451-4b88-b1f4-1f3889049e57" 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 placed in the variable description .

Any idea how I can align the text?

+6
source share
1 answer

My solution shows a simple JRXML , which is the desired result regardless of the tools someone is using, for example. iReport GUI, dynamic reports or java code for developing Jasper reports.

First, define a style that corrects the indent by pulling the first line a few pixels to the left and pushing the entire rectangle equal width to the right:

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

Secondly, this style applies to reportElement 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 can change the style values ​​to suit your needs.

I adapted the input from Marker Alignment in Jasper reports that use dynamic api reports, and the Jasper Report HTML bullet hanging indent , where it is displayed through a graphical interface, which was impossible in my case using iReport Designer 4.5.1, because there is no way apply the add-on directly to textField .

+8
source

Source: https://habr.com/ru/post/977187/


All Articles