user6385735
user6385735

Reputation: 151

Some currency Symbol in Jasper report is not coming

I have created a jasper report template using jaspersoft studio and I am populating the template using java code. I have some data in the report which needs to be localize and for that I am seeting the "locale" by below code in java.

Locale locale = new Locale("zh", "CN");
templateParameters.put("REPORT_LOCALE", locale); //A map to pass to report

I have also tried -

Locale locale = java.util.Locale.CHINA;

In populated report "Number formatting" is there but currecny symbol is missing(only dollar, pound, euro symbols are coming) Below is the code I have used in jasper report to populate the text field -

NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{Param_Name})

I would be very thankful if someone could pointout the mistake or provide some suggestion.

Upvotes: 2

Views: 3548

Answers (1)

Alex K
Alex K

Reputation: 22867

I believe that your issue related with font supporting.

We should use Font Extensions in case using JRPdfExporter.

I tried to use font with Chinese support and in this case everything is OK.I don't know why using a ton of another fonts is not helping

Example

Java code

Map<String, Object> params = new HashMap<>();
params.put(JRParameter.REPORT_LOCALE, Locale.CHINA);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());

Report template

There are 4 textFields in jrxml file: two using font with Chinese support and another 2 - without it.

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Show currency" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <parameter name="value" class="java.lang.Double" isForPrompting="false">
        <defaultValueExpression><![CDATA[1234.567]]></defaultValueExpression>
    </parameter>
    <title>
        <band height="70">
            <textField>
                <reportElement x="10" y="10" width="300" height="15"/>
                <textElement>
                    <font fontName="Sharp Dawn"/>
                </textElement>
                <textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance(new Locale("zh", "CN")).format($P{value})]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="10" y="25" width="300" height="15"/>
                <textElement>
                    <font fontName="Sharp Dawn"/>
                </textElement>
                <textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{value})]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="3" y="40" width="300" height="15"/>
                <textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{value})]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="3" y="55" width="300" height="15"/>
                <textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance(new Locale("zh", "CN")).format($P{value})]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

Output result

The pdf file generated with help of JRPdfExporter looks like

enter image description here

The Yuan symbol is showing only for first group.

Upvotes: 2

Related Questions