views:

652

answers:

2

how to escape special characters in jasperreports ?

I want to escape special characters like :- é, â, è, ^, @ in jasper reports, so is there any way we can escape this characters ?

A: 

Try this:

  • instead of 'é' use '\u00E9'
  • instead of 'â' use '\u00E2'
  • instead of 'è' use '\u00E8'

etc.

Boris Pavlović
I have string comming from oracle, at a short i want to replace all the special character is it possible ? is there any api for it ?
Bihag Raval
then check what's the encoding of your db, then check what's the encoding of your jasperreports templates. bear in mind that oracle jdbc has problems transforming some special ms word characters into unicode
Boris Pavlović
A: 

If you want to escape special XML characters like <, > you can use CDATA:

<staticText>
    <reportElement x="0" y="0" width="100" height="14"/>
    <textElement/>
        <text><![CDATA[This is a test:<                 ]]></text>
</staticText>

Special characters like é, â, è should work great if you specify the character encoding at the beginning of the jrxml file and encode the file correctly.

<?xml version="1.0" encoding="UTF-8"?>

If the exported report shows invalid characters you should check the jasper export. For instance for pdf export can find info here.

asalamon74