使用JasperReports生成PDF中的缩进

Abs*_*Abs 7 pdf-generation indentation jasper-reports export-to-pdf

我有一个HTML存储在数据库中:

<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>
Run Code Online (Sandbox Code Playgroud)

我使用JasperReports textField在PDF中显示这段HTML,上面的HTML应该在生成的PDF中显示如下.

  • 假装你正在与一位忙碌的同事交谈,并且必须用一句话总结你的整个问题:你可以包括哪些细节可以帮助某人识别和解决你的问题?
  • 拼写,语法和标点符号很重要!请记住,这是其他人会看到的问题的第一部分 - 您希望给人留下好印象.如果您不习惯用英语写作,请让朋友为您校对.
  • 如果您遇到问题,总结问题,写标题最后 -有时写作问题的先休息可以更容易说明问题. 

但是这个HTML显示为:

在此输入图像描述

来自jrxml文件的片段:

<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>
Run Code Online (Sandbox Code Playgroud)

描述变量中包含HTML .

任何想法如何对齐文本?

tim*_*ber 8

我的解决方案显示了plain JRXML,这是独立于某人使用的工具所需的结果,例如iReport GUI,动态报告或java代码设计Jasper报告.

首先定义一个样式,该样式可以修正第一行的缩进,将某些像素向左拉,并将整个框向右推宽度相同:

<style name="hanging-indentation-style">
    <box leftPadding="23"/>
    <paragraph firstLineIndent="-23"/>
</style>
Run Code Online (Sandbox Code Playgroud)

其次,这种风格应用到reportElementtextField:

<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>
Run Code Online (Sandbox Code Playgroud)

根据您的字体大小,您可以根据需要改变样式值.

我调整了Jasper Reports中Aligning Bullets的输入,其中使用了动态报告api,Jasper报告HTML子弹悬挂缩进,通过GUI显示,在我的情况下使用iReport Designer 4.5.1是不可能的,因为有没有选项直接应用填充到textField.