7
votes

I'm generating a multi-language report using JasperReports in Java.

When I generate pdf, few languages do not display properly.

enter image description here

Whereas, When I generate Excel, The report is generated properly with the correct language.

enter image description here

searching on the internet I found pdf font is not supported.

here my code set to font:

 Style rowStyle = new Style();
 Font font = new Font(FONT_SIZE_SMALL, "Noto Sans", false, false, false);
 font.setPdfFontName("Noto Sans");
 font.setPdfFontEncoding(Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing);
 font.setPdfFontEmbedded(false);
 rowStyle.setFont(font);

any idea how to solve?

2
For future users, the problem here was that OP used a font that did not support the language (Indian), if you like to test support see stackoverflow.com/a/56777934/5292302Petter Friberg

2 Answers

5
votes

Have you tried setting DEBUG jasper reports logging to check which font is getting used when the PDF is rendered? (example log4j setup below)

<category name="net.sf.jasperreports">
    <priority value="DEBUG" />
</category>

For example you should see DEBUG log of a font being loaded by jasper:

DEBUG SimpleFontFace:177 - Loading font fonts/ARIALUNI.TTF

And if you are using jasper font extension (described below), you should see something like:

 DEBUG FontExtensionsRegistry:88 - Loading font extensions from net/sf/jasperreports/fonts/jasperreports-fonts.xml

Are you including the font in the classpath? I have successfully used a custom built jar similar to what is described in this post in the docs: https://community.jaspersoft.com/wiki/adding-fonts-embedding-pdf

I would also try setPdfFontEmbedded(true). In the generated PDF you can determine if the font is included in the report if you open the PDF in Adobe Acrobat Reader, and see if it is listed under File -> Properties... -> Fonts tab (see screenshot). It should have (Embedded) or (Embedded subset) next to the font name. enter image description here

Edit

Above steps can help debug issues like this. It turns out that the "Noto Sans" font doesn't support Indian characters, using "Arial Unicode MS" works though.

In Docs, you can see how many languages are supported.

0
votes
--Use below code 

 `Style rowStyle = new Style();
 Font font = new Font(FONT_SIZE_SMALL, "Arial Unicode MS", false, false, false);
 font.setPdfFontName("Arial Unicode MS");
 font.setPdfFontEncoding(Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing);
 font.setPdfFontEmbedded(false);
 rowStyle.setFont(font);`