Jasper Report:使用HTML标记在文本字段中将文本对齐为中心 [英] Jasper Report : Aligning text as center in text field using HTML markup

查看:230
本文介绍了Jasper Report:使用HTML标记在文本字段中将文本对齐为中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Jasper报告来显示从数据库检索到的文本.文本为HTML格式.在PDF中显示时,我需要对文本进行样式设置和对齐.这是来自数据库的示例HTML文本

I have created a Jasper Report to display text retrieved from DB. The text is in the HTML format. I have a requirement to style and align the text when displaying in PDF. This is a sample HTML text from DB

<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>

粗体和段落标记可以正常工作.但是该字体不适用于大小4.必须有一条居中标记,该标记必须居中对齐.查看Jasper文档中心标签未在受支持的标签中列出. http://jasperreports.sourceforge.net/sample.reference/styledtext/index.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. Looking at the Jasper documentation center tag is not listed in supported tags. http://jasperreports.sourceforge.net/sample.reference/styledtext/index.html

我尝试使用样式和rtf标记进行居中对齐,但没有用. 我还有什么其他方法可以使文本对齐以文本字段中某些行的中心为中心?

I tried center alignment with styled and rtf markup, it didn't work. 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.

推荐答案

字体大小

我看不到您的字体大小命令有任何问题,请确保您拥有markup="html"并且"已正确转义,您可以尝试将其替换为'

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 '

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>

将呈现

文本对齐

使用不同的markup(样式,rtf,html),您只能设置文本的外观格式(颜色,粗体,下划线等).

with different markup (styled,rtf,html) you can only format how the text looks (color,bold,underline ecc).

此功能用于生成样式文字.

报价 Teodord(碧玉报告工作人员)

Quoting Teodord (jasper report staff)

该对齐方式不在受支持的样式中,因为它与 文字字符的外观,但有关您如何布置它们.我们不可以 更改同一文本字段元素中文本的对齐方式.

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.

您有什么选择?

  1. 用空格左填充文本,您可以创建自己的静态方法,用es左填充文本. &nbsp;取决于文本长度.

尝试使用<hc:html>组件,这将呈现html图像. (不再是文字,而是图片...)

Try the <hc:html> component, this will render an image of you html. (not text anymore but image...)

对JasperReport或JasperPrint进行后期处理以移动元素...(请注意,它必须是一个单独的元素)

Post process the JasperReport or JasperPrint to move the element... (note it needs to be a separate element)

不是很多..那么为什么不没有....

not much.. so why not do without....

这篇关于Jasper Report:使用HTML标记在文本字段中将文本对齐为中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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