简体   繁体   English

Jasper报告:使用HTML标记将文本对齐为文本字段中的中心

[英]Jasper Report : Aligning text as center in text field using HTML markup

I have created a Jasper Report to display text retrieved from DB. 我创建了一个Jasper报告来显示从DB检索的文本。 The text is in the HTML format. 文本采用HTML格式。 I have a requirement to style and align the text when displaying in PDF. 我需要在以PDF格式显示时设置样式并对齐文本。 This is a sample HTML text from DB 这是来自DB的示例HTML文本

<html>
<p><b>This is Bold text</b></p>
<p>  This is a paragraph whith indent</p>
<p>This is a paragra with no indent</p>
<p><center>This text should be centered</center></p>
<p><font size="4">This text should be of font size 4</font></p>
</html>

The bold and paragraphs tags works fine. 粗体和段落标签工作正常。 But the font doesn't work for size 4. There is a center tag for a line which has to be aligned center. 但是字体不适用于尺寸4.有一条线的中心标记必须对齐中心。 Looking at the Jasper documentation center tag is not listed in supported tags. 查看Jasper文档中心标记未列在受支持的标记中。 http://jasperreports.sourceforge.net/sample.reference/styledtext/index.html http://jasperreports.sourceforge.net/sample.reference/styledtext/index.html

I tried center alignment with styled and rtf markup, it didn't work. 我尝试使用样式和rtf标记进行中心对齐,但它不起作用。 Is there any other way I can achieve the text alignment as center for some lines in text field? 有没有其他方法可以实现文本对齐作为文本字段中某些行的中心?

Also let me know if I am using the font tag in wrong way. 如果我以错误的方式使用字体标记,也请告诉我。

Font size 字体大小

I can't see nothing wrong with your font size command, make sure that you have markup="html" and that the " is escaped properly you can try be replacing it with ' 我看不出你的字体大小命令有什么问题,请确保你有markup="html"并且"正确转义你可以尝试用'替换它'

This textFieldExpression 这个textFieldExpression

<textField>
    <reportElement x="132" y="0" width="126" height="30" uuid="0328a547-49c7-402c-bcb0-ae2a8fba4fb3"/>
    <textElement markup="html"/>
    <textFieldExpression><![CDATA["<p><font size=\"1\">Small</font>&nbsp;<font size=\"3\">Big</font></p>"]]></textFieldExpression>
</textField>

will render 将呈现

小大

Text alignment 文字对齐

with different markup (styled,rtf,html) you can only format how the text looks (color,bold,underline ecc). 使用不同的markup (样式,rtf,html),您只能格式化文本的外观(颜色,粗体,下划线ecc)。

This feature is for producing styled text . 此功能用于生成样式文本

Quoting Teodord (jasper report staff) 引用 Teodord(碧玉报告人员)

The alignment is not among supported styling because it is not about how text characters look , but about how you lay them out. 对齐不在支持的样式之间,因为它不是关于文本字符的外观 ,而是关于如何布局它们。 We cannot change the alignment of text within the same text field element. 我们无法在同一文本字段元素中更改文本的对齐方式。

What are you options? 你有什么选择?

  1. Left padding text with space, you could create your own static method that left pad your text with es. 使用空格左边填充文本,您可以创建自己的静态方法,用es填充文本。 &nbsp; depending on the text length. 取决于文本长度。

  2. Try the <hc:html> component, this will render an image of you html. 试试<hc:html>组件,这将呈现你的html图像。 (not text anymore but image...) (不再是文字了,但图片......)

  3. Post process the JasperReport or JasperPrint to move the element... (note it needs to be a separate element) 后处理JasperReport或JasperPrint来移动元素...(注意它需要是一个单独的元素)

not much.. so why not do without.... 没多大..所以为什么不做不...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM