Search code examples
jspfontsjasper-reports

Jasper show Chinese word to pdf


how to show chinese word to pdf using jsp ?

when I using Jasper Studio to see the pdf

chinese word is no problem

but when I using JSP to show pdf

I get the error message

Font "kaiu" is not available to the JVM. See the Javadoc for more details.

how to fix it ?


Solution

  • You can create a Font extension jar with iReport and export it out and add it to your classpath and everything should be fine. See this blog post for an example: http://mdahlman.wordpress.com/2010/05/28/jaspersoft-v3-7-font-extensions/

    Second option is copy fonts in reports related folder and create style tag, then map the style to component.

    <style name="yourHeader" fontName="Verdana" fontSize="9" isBold="true" pdfFontName="reports/fonts/fontname.ttf" pdfEncoding="Cp1252" isPdfEmbedded="true"/>
    

    PdfEncoding is required attribute.

            <textField isBlankWhenNull="false">
                <reportElement key="textField" style="yourHeader" x="1" y="1" width="200" height="20" />
                <textElement>
                    <font isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$R{text}]]></textFieldExpression>
            </textField>
    

    Font is available in your machine, but they aren’t registered as font extensions refer below link

    http://www.cnblogs.com/keyliu/archive/2012/07/19/2600037.html