0

I'm currently trying to display Japanese characters in a report produced using JasperReports 5.2.0. The Japanese characters in the document are lost. When I examine the PDF properties I see that only one font exists in the document: Helvetica.

Through some research I've found that the IText library is responsible for producing the PDF export. JasperReports 5.2.0 uses itext-2.1.7.js2. This jar does not contain international character sets. Instead, this is provided separately in IText-Asian, under a different license (AGPL).

The JasperReports library tutorial (http://community.jaspersoft.com/wiki/jasperreports-library-tutorial) says:

To simplify the use of the font settings, a new element was introduced: .

Report fonts are report level font definitions that ca be used as default or base font settings in other font definitions throughout the entire report. Since the support for international characters is somehow tied to the iText library, you can find more details about how to create PDF documents in different languages and different character sets in the iText documentation.

This seems to imply that the international characters are locked behind the later versions of the IText library.

Is it possible to embed international character fonts into a PDF without upgrading to JasperReports 6.x, or IText 5.x?

Update:

I have tried to set up a simple font extension using a JasperReports_extensions.properties with the contents:

net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.test=path/to/fonts/fonts.xml

This XML file contains:

    <fontFamily name="Arial Unicode MS">
        <normal>path/to/fonts/testJA/ARIALUNI.TTF</normal>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
            <export key="net.sf.jasperreports.html">'Arial Unicode MS', Arial, Helvetica, sans-serif</export>
            <export key="net.sf.jasperreports.xhtml">'Arial Unicode MS', Arial, Helvetica, sans-serif</export>
        </exportFonts>
        <locales>
            <locale>ja_JP</locale>
        </locales>
    </fontFamily>

The target directory contains the windows ARIALUNI.TTF file. (Note, not intending on using this, only using it currently for debugging).

SlopeOak
  • 175
  • 1
  • 10
  • Have you tried font-extensions? – Petter Friberg Feb 09 '16 at 16:51
  • I have tried font extensions. I created a font.xml pointing to a unicode font for ja_JP; the unicode characters weren't displayed which made me believe that the support for Asian characters is missing from IText. Is that not the case? – SlopeOak Feb 10 '16 at 10:30
  • If you improve your question with the font you use (downloadable?), some example text you like to print probably I can test it. Create a [mcve] – Petter Friberg Feb 10 '16 at 10:36
  • Some useful links on font-extensions and testing font in pdf, http://stackoverflow.com/questions/33940126/how-can-i-display-%C2%A3%E2%84%A6%E2%82%AC%CE%B1%CF%80%E2%85%94-in-jasperserver-pdf-using-ireport, http://stackoverflow.com/questions/34041619/jasper-reports-pdf-doesnt-export-cyrillic-values http://stackoverflow.com/questions/35127956/how-can-i-test-if-my-font-is-rendered-correctly-in-pdf – Petter Friberg Feb 10 '16 at 10:38
  • I will adapt it to an SSCCE as soon as I can. It may take me a while to strip it down to the basics. For now I've added the contents of the fonts.xml and jasperreports_extensions.properties. – SlopeOak Feb 10 '16 at 10:51
  • Some very basic text: aあbaば - This displays as "aba" currently. – SlopeOak Feb 10 '16 at 11:04
  • I can confirm that it works with iText 5.5.4 (font-extensions, generate by me), consider to update atleast to check that you have correct font-extension. – Petter Friberg Feb 10 '16 at 11:39
  • Ah. You're using a later version of IText than I am. This brings me back to the original question. I'm license locked into IText 2.1.7. The latest version of IText changes the licensing to AGPL which we're unable to support at this time. Is it not possible to export the characters using a lower version of IText? – SlopeOak Feb 10 '16 at 13:42
  • I would first try with latest and see that it works, then you at least know that itext version is the problem, not your font-extensions. – Petter Friberg Feb 10 '16 at 14:04
  • I followed your test code in http://stackoverflow.com/questions/35127956/how-can-i-test-if-my-font-is-rendered-correctly-in-pdf and noticed that IText 2.1.7.js2 can successfully load the font. So it's my configuration. Somewhere. Not a clue where yet. So it pretty much answers this question: It does work, but I've got it wrong somewhere. – SlopeOak Feb 10 '16 at 16:08
  • I would say font-extension is not correct... I download a font from internet and made this font-extension to test http://www.jdd.it/stacktrace/ArialUnicodeMS.jar (its like 15M but only due to the very large .ttf font) – Petter Friberg Feb 10 '16 at 16:21
  • if you like you can test it, set it in your classpath and run report... (i have a really hard time to test your setup, need to download old libs...) – Petter Friberg Feb 10 '16 at 16:22
  • The font name on your text field needs to be "Arial Unicode MS", don't use bold or other strange stuff.... which encoding did you use in the test IDENTITY_H? – Petter Friberg Feb 10 '16 at 16:24
  • Yes I was using Identity-H. I followed your FontFamilies XML example, and although it didn't pick up my font in the produced PDF, I've noticed that the SimpleFontFactory is now being hit through generation of the report - which wasn't happening before. I'll debug from here and see where I can get to. – SlopeOak Feb 11 '16 at 10:43
  • Have you tried with that jar in classpath, it should work as it is... – Petter Friberg Feb 11 '16 at 11:38

0 Answers0