我在数据库中存储了一段 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. </li>
</ul>
我正在使用 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>
HTML 输入 说明 多变的。
知道如何对齐文本吗?
最佳答案
我的解决方案显示了普通 JRXML
这是独立于某人正在使用的工具的期望结果,例如iReport GUI、动态报告或设计 Jasper 报告的 Java 代码。
首先定义一个样式,它纠正缩进,将第一行向左拉一些像素,并将整个框向右推相同的宽度:
<style name="hanging-indentation-style">
<box leftPadding="23"/>
<paragraph firstLineIndent="-23"/>
</style>
二、此样式适用于
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>
根据您的字体大小,您可以改变样式值以满足您的需要。
我改编了来自 Aligning Bullets in Jasper Reports 的输入,其中使用了动态报告 api,以及 Jasper Report HTML bullet hanging indent ,它通过 GUI 显示,这在我使用 iReport Designer 4.5.1 的情况下是不可能的,因为没有选项可以将填充直接应用于
textField
.
关于jasper-reports - 使用 JasperReports 在生成的 PDF 中缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26551095/