Use multiple fonts for one text box in jasper reports

I have a field that displays "To: NAME" . Here, "To" is static and "NAME" is a variable. Therefore, I used the same text field attr and "To:" + $ F {name} as an expression. Now the problem is that I have to use two separate fonts for "To" and "Name". I tried using the style, but I have to skip something. Could you help me?

NB: I cannot use static text for “To” and a text field for the “name” field, since the horizontal alignment for them should be centered.

+5
source share
1 answer

ok, I can achieve this by modifying jasper xml as follows →

            <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 this helps others.

+5
source

All Articles