Search code examples
utf-8jasper-reportsexport-to-pdf

Display character SQUARE M SQUARED (\u33a1) in generated pdf report


I am using following code for jasper pdf report to display character M SQUARED (\u33a1)

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

<textField isStretchWithOverflow="true">
            <reportElement x="0" y="0" width="609" height="20" uuid="df8665ef-2226-4aaa-bd04-09805582eaef"/>
            <textElement verticalAlignment="Middle">
                <font fontName="SomeCustFont" size="20" pdfEncoding="Cp1252" isPdfEmbedded="true"/>
            </textElement>
            <textFieldExpression><![CDATA["Squared M : \u33a1"]]></textFieldExpression>
        </textField>

For this code, I am not able to see the unicode character in PDF. It is simply blank. But in XLSX, I am able to see the character. I tried following:

  1. Remove pdfEncoding
  2. Set isPdfEmbedded="false"

But no luck

Update: It seems, the custom font I am using is not supporting squared m character. I cannot add a new font or update existing custom font. But I can use any or in-built fonts for that particular character. How can I achieve this using in-built font?

I tried:

fontName="Courier" pdfFontName="Courier" This in-built font for jasper supported that character but I am getting error as font cannot be located.


Solution

  • The main problem here was \u33a1 is an extended ASCII unicode. Most of the free fonts don't support this. So instead of this squared m, I used english 'm' character followed by superscript 2 unicode \u00b2 which is available in almost all fonts.

    \u33a1 -> m\u00b2