我有一段 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 中应该像这样显示。
- 假设您正在与一位忙碌的同事交谈,并且必须用一句话总结您的整个问题:您可以包含哪些详细信息来帮助别人识别并解决您的问题?
- 拼写、语法和标点符号都很重要!请记住,这是其他人会看到的问题的第一部分 - 您想给人留下好印象。如果您不习惯用英语写作,请请朋友为您校对。
- 如果您无法总结问题,请写下标题last- 有时先写下问题的其余部分可以更容易地描述问题。
但这个 HTML 显示为:
片段来自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 被输入描述多变的。
知道如何对齐文本吗?
我的解决方案显示简单JRXML
这是独立于某人使用的工具的期望结果,例如iReport GUI、动态报告或设计 Jasper 报告的 java 代码。
首先定义一个样式,它纠正将第一行向左拉一些像素并将整个框向右推相同宽度的缩进:
<style name="hanging-indentation-style">
<box leftPadding="23"/>
<paragraph firstLineIndent="-23"/>
</style>
其次,这种风格适用于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>
根据您的字体大小,您可以改变样式值以满足您的需求。
我改编了来自对齐 Jasper 报告中的项目符号 https://stackoverflow.com/a/16485369/3246440,其中使用动态报告 api,并且Jasper Report HTML 项目符号悬挂缩进 https://stackoverflow.com/a/13229466/3246440,它是通过 GUI 显示的,在我使用 iReport Designer 4.5.1 的情况下这是不可能的,因为没有选项可以直接将填充应用于textField
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)