jasper-reports - 使用 JasperReports 在生成的 PDF 中缩进

标签 jasper-reports pdf-generation indentation 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>

我正在使用 JasperReports textField 在 PDF 中显示这段 HTML,上面的 HTML 应该像这样在生成的 PDF 中显示。

  • 假设您正在与一位忙碌的同事交谈,并且必须用一句话总结您的整个问题:您可以包含哪些细节来帮助他人识别和解决您的问题?
  • 拼写、语法和标点符号很重要!请记住,这是其他人会看到的问题的第一部分 - 您想给人留下好印象。如果您不习惯用英语写作,请让 friend 为您校对。
  • 如果您在总结问题时遇到困难,请将标题写在最后——有时先写下问题的其余部分可以更容易地描述问题。


  • 但是这个 HTML 显示为:

    enter image description here

    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>
    

    二、此样式适用于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>
    

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

    我改编了来自 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/

    相关文章:

    c - 为什么缩进会破坏源代码格式?

    asp.net - Visual Studio 2005 : Is there an easy way to indent correctly in an ASPX file?

    java - 通过Servlet或JSP将JasperReport的报告导出为pdf

    java - 使用 Struts2 生成报告时出现 ClassCastException

    java - Grails 中 pdf 生成中的 NoClassDefFoundError 异常

    java - pdf转换使用java库

    java - fillReport 函数期间 PermGen Space 错误

    jasper-reports - JasperReports 6.12.2 中的文本字段动态高度

    pdf - 通过 Windows 命令行将 TIFF 转换为 PDF

    Vim 编辑不同文件时混合缩进样式