使用JasperReports生成PDF中的缩进 [英] Indentation in generated PDF using JasperReports

查看:1053
本文介绍了使用JasperReports生成PDF中的缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<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文本字段在PDF中显示这段HTML,上面的HTML应显示在生成的PDF中就像这样。

I am displaying this piece of HTML in a PDF using a JasperReports text field , the above HTML should display like this in the generated PDF.


  • 假装你正在与一位忙碌的同事交谈,并且必须总结你的整个问题。一句话:你可以包括哪些细节可以帮助别人识别并解决你的问题?

  • 拼写,语法和标点符号很重要!请记住,这是其他人会看到的问题的第一部分 - 您希望给人留下好印象。如果您不习惯用英语写作,请让朋友为您校对。

  • 如果您在总结问题时遇到问题,请写下标题 last - 有时首先编写问题的其余部分可以更容易地描述问题。  

    • 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?
    • 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.
    • 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. 
    • 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 description 变量。

      我知道如何对齐文本?

      推荐答案

      我的解决方案显示简单 JRXML 这是独立于某人使用的工具的理想结果,例如iReport GUI,动态报告或java代码设计Jasper报告。

      My solution shows the plain JRXML which is the desired result independent from the tools someone is using, e.g. iReport GUI, dynamic reports or java code designing Jasper reports.

      首先定义一个样式,用于修正第一行向左拉一些像素并按下整个框的缩进右边相同的宽度:

      First define a style, which corrects the indentation pulling the first line some pixels to the left and pushes the whole box the same width to the right:

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

      其次,此样式适用于 reportElement textField

      Second, this style is applied to the 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>
      

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

      Depending on your font size you may vary the style values to fit your needs.

      我调整了来自在Jasper报告中对齐项目符号的输入,其中使用了动态报告api ,以及 Jasper报告HTML项目符号悬挂缩进,它通过GUI显示,在我的情况下使用iReport是不可能的Designer 4.5.1,因为没有选项可以直接将填充应用于 textField

      I adapted input from Aligning Bullets in Jasper Reports, where dynamic reports api is used, and Jasper Report HTML bullet hanging indent, where it is shown through the GUI, which was not possible in my case using iReport Designer 4.5.1, because there is no option to apply padding directly to a textField.

      这篇关于使用JasperReports生成PDF中的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆