3

Working in JasperReports:

<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true" 
forecolor="red">Instruction and instruction</style>

Not Working in JasperReports:

<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction & instruction</style>

Why this is happening?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Ishwar Pohani
  • 113
  • 1
  • 1
  • 10

2 Answers2

2

I have used &amp;amp; instead of "&" and it is working in jasper report.

<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction &amp;amp; instruction</style>

//In text filed i have used style tag.

<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                <reportElement
                    x="0"
                    y="0"
                    width="290"
                    height="15"
                    key="textField"
                    isRemoveLineWhenBlank="true"/>
                <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" rightPadding="5" bottomBorder="None" bottomBorderColor="#000000"/>
                <textElement textAlignment="Center" isStyledText="true">
                    <font size="9"/>
                </textElement>
            <textFieldExpression   class="java.lang.String"><![CDATA[<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction &amp;amp; instruction</style>]]></textFieldExpression>
            </textField>
Ishwar Pohani
  • 113
  • 1
  • 1
  • 10
1

Try to use &amp; instead of using & symbol.

The working sample:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... whenNoDataType="AllSectionsNoDetail">
    <style name="style1" forecolor="#FF0000" fontName="Serif" isBold="true" isItalic="true"/>
    <title>
        <band height="182" splitType="Stretch">
            <staticText>
                <reportElement style="style1" x="27" y="15" width="515" height="20"/>
                <textElement/>
                <text><![CDATA[Instruction and instruction]]></text>
            </staticText>
            <staticText>
                <reportElement style="style1" x="27" y="46" width="515" height="20"/>
                <textElement/>
                <text><![CDATA[Instruction & instruction]]></text>
            </staticText>
            <staticText>
                <reportElement x="27" y="78" width="515" height="20"/>
                <textElement markup="styled"/>
                <text><![CDATA[<style isBold='true'>Instruction and instruction</style>]]></text>
            </staticText>
            <staticText>
                <reportElement x="27" y="108" width="515" height="20"/>
                <textElement markup="styled"/>
                <text><![CDATA[<style isBold='true'>Instruction &amp; instruction</style>]]></text>
            </staticText>
        </band>
    </title>
</jasperReport>

Note: The styled markup is using in this sample.

The result will be:

The preview in iReport


For more details you can view Creating Styled Text Using a Markup Language post and my answer on Style a text field in JasperReports question.

Community
  • 1
  • 1
Alex K
  • 22,315
  • 19
  • 108
  • 236
  • Thanks, But it is still not working. If i write "&" out of style tag it is working but, when i write it in style tag, it not works. – Ishwar Pohani Oct 30 '12 at 11:05
  • @IshwarPohani Can you add the exact snippet from your *jrxml* to your question? I'll try to check your expression – Alex K Oct 31 '12 at 07:02
  • Alex, I have found solution which worked for me. May be you are right but not worked in my scenerio. What i have found, i have posted. – Ishwar Pohani Sep 24 '13 at 10:45