jasper report Multi language- cannot display font while generating pdf in spring boot
Asked Answered
F

2

7

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?

Fatuous answered 12/6, 2019 at 10:58 Comment(1)
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 https://mcmap.net/q/1624794/-get-date-of-tomorrow-using-jstlRobespierre
M
5

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.

Myasthenia answered 22/6, 2019 at 20:20 Comment(3)
I did the same but not working and also tried setPdfFontEmbedded(true).Fatuous
Also by not working do you mean the font does not show up like in the screenshot as embedded?Myasthenia
thank you for your response I found the solution noto sans don't support Indian language so I change to Arial Unicode MS and works.Fatuous
D
0
--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);`
Diplomate answered 25/6, 2019 at 12:5 Comment(1)
Honestly this Q/A is getting confusional, since your actual problem was that you where using a font that was not support by language used (language specification where neither included in question, hence impossible for someone else to know)Robespierre

© 2022 - 2024 — McMap. All rights reserved.