Use multiple fonts for a single text field in jasper reports

余生颓废 提交于 2019-12-09 11:59:38

问题


I have a field which displays "To : NAME". Here "To" is static and "NAME" is a variable. So I have used a single Text Field attr and "To: " + $F{name} as an expression. Now, the problem is, I have to use two separate fonts for "To" and "Name". I've tried using style but I must be missing something. Could you please help me out?

N.B : I cannot use static text for "To" and text field for "name" field as horizontal alignment for these has to be center being together.


回答1:


ok, I'm able to achieve this modifying the jasper xml in the following way -->

            <textField>
                <reportElement x="36" y="192" width="329" height="16"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled">
                    <font size="10"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA["<style fontName='ChronicleTextG1_Italic'>To: </style><style fontName='ChronicleTextG1_Roman'>" + $F{TO_NAME} + "</style>"]]></textFieldExpression>
            </textField>

Hope it helps other.




回答2:


You just can do this within the iReport expression editor without the need for manually editing the jrxml.

For HTML markup, this looks like so within the expression editor (set font 'ChronicleTextG1_Italic' directly on the field as usual. This will take care of the font for 'To:'):

"To: <font face='ChronicleTextG1_Roman'>" + $F{TO_NAME} + "</font>"


来源:https://stackoverflow.com/questions/16294372/use-multiple-fonts-for-a-single-text-field-in-jasper-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!