Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

  • so I added noto sans font.
  • creating a custom jar font file from jaspar studio.
  • added in classpath.

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?

like image 598
Akash Shah Avatar asked Jun 12 '19 10:06

Akash Shah


1 Answers

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.

like image 120
camtastic Avatar answered Sep 29 '22 07:09

camtastic