Search code examples
jasper-reportsireport

Use multiple fonts for a single text field in jasper reports


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.


Solution

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