Font is not available to the JVM with Jasper Reports
Asked Answered
L

20

112

I'm trying to generate report with DynamicJasper, but I'm getting the following error:

net.sf.jasperreports.engine.util.JRFontNotFoundException:  
                                 Font 'Arial' is not available to the JVM.   

msttcorefonts is installed, but I guess the JVM is not using any fonts from it.

I'm using Ubuntu 10.04.

How can I fix this?

Louvenialouver answered 28/9, 2010 at 10:46 Comment(7)
I'm actually ignoring it ... just set the following "net.sf.jasperreports.awt.ignore.missing.font=true" bad idea... but solves the problem for a moment....Louvenialouver
You would need to install microsoft fonts in Ubuntu, refer this link for information .. embraceubuntu.com/2005/09/09/installing-microsoft-fontsFossick
where do you set this? i'm working with an embedded version of jasperreports in jbilling where no jasperreports.properties file exists to edit.Olympia
https://mcmap.net/q/195972/-jasper-report-font-error Refer itDogeatdog
@Andrew, this does not seem like a good solution (I know question is old), but maybe its better that we avoid reports inconsistency, I have passed on answer.Raffarty
use this :- community.jaspersoft.com/wiki/custom-font-font-extensionBaloney
jasperreports-fonts-6.8.0 adding this jar worked for me.Falsity
E
77

I tried installing mscorefonts, but the package was installed and up-to-date.

sudo apt-get update
sudo apt-get install ttf-mscorefonts-installer

I tried searching for the font in the filesystem, with:

ls /usr/share/fonts/truetype/msttcorefonts/

This folder just had the README, with the correct instructions on how to install.

cat /usr/share/fonts/truetype/msttcorefonts/README

You need an internet connection for this:

sudo apt-get install --reinstall ttf-mscorefonts-installer

I re-installed ttf-mscorefonts-installer (as shown above, making sure to accept the EULA!) and the problem was solved.

Endolymph answered 25/10, 2011 at 13:54 Comment(11)
FYI on other linux flavours try sudo apt-get install msttcorefontsOmniumgatherum
for CentOS and RHEL6 how do you solve the EULA problem? yum install doesn't give you any option to accept, any ideas?Olympia
What about the most common windows OS?Eccrinology
This is a work around on a single pc, it will not solve any encoding problems, the correct way is to use font-extensions I have posted an answerRaffarty
Package ttf-mscorefonts-installer is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'ttf-mscorefonts-installer' has no installation candidateBrok
Package msttcorefonts is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'msttcorefonts' has no installation candidateBrok
For Cloud VM askubuntu.com/questions/659305/…Brok
The answer is correct for the situation when we had fonts already installed but without accepted license. Here are the steps to perform in case you are about to perform first automated installation correctly: sudo echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections && apt-get install -y -q ttf-mscorefonts-installerChatham
How to do it on Amazone Linux?Pasia
For it to take effect I had to reboot the machine after installing the fonts.Partheniaparthenocarpy
This is the wrong way. The answer regarding font extensions is the right way. Documentation explains why, as does that answer.Horrible
R
47

JasperReports raises a JRFontNotFoundException in the case where the font used inside a report template is not available to the JVM as either as a system font or a font coming from a JR font extension. This ensure that all problems caused by font metrics mismatches are avoided and we have an early warning about the inconsistency.

Jasper reports is trying to help you in your report development, stating that it can not export your report correctly since it can not find the font defined in TextField or StaticText

<font fontName="Arial"/>

Yes you can disable this by setting net.sf.jasperreports.awt.ignore.missing.font to true but you will have export inconsistencies.

Yes you can install the font as JVM system font (but you need to do it on every PC used that may generate report and you can still have encoding problems).

The correct way!

Use Font Extensions!, if you like to create your own (see link below), jasper reports also distributes a default font-extension jar (jasperreports-fonts-x.x.x.jar), that supports fontName DejaVu Sans, DejaVu Serif and DejaVu Sans Mono

<font fontName="DejaVu Sans"/>

From the JasperReport Ultimate Guide:

We strongly encourage people to use only fonts derived from font extensions, because this is the only way to make sure that the fonts will be available to the application when the reports are executed at runtime. Using system fonts always brings the risk for the reports not to work properly when deployed on a new machine that might not have those fonts installed

Links on StackOverflow on how to render fonts correctly in pdf

Checklist on how to render font correctly in pdf

Generate font-extensions with JasperSoft Studio

Generate font-extensions with iReport

Raffarty answered 22/2, 2016 at 8:56 Comment(4)
Could you tell me the reason why Jasper and JVM could not render the PDF with a Font which exists in the system (located at C:\windows\fonts), instead I have to create a Jar Font extension and add it as a library into the project's class path (I'm using Java and Eclipse). I tried to google for the answer but haven't found an understandable explanation. Also I see this exporting-pdf-font-problems too with Apache FOP (no font extension needed but I had to create a font-metric-file and did some extra configurations for the font to be rendered correctly)Decrepitate
@Decrepitate it all comes down to the itext library that is generating the pdf, itext to correctly render fonts needs font-extensions (where not only font is included but also encoding, if embedded ecc is specified). If you do not provide this, itext will do what they call "best effort" to render your font. You are not doing what we need (written in documentation), lets do our best, but the fault is yours. Hence the accepted answer on this question is not correct!, Font extensions are needed, if you do not supply you will have to live with whatever is created.Raffarty
thanks for the answer, but still I only get it that the font issue is du to the way iText library works. May be this font things is way beyond my technical ability to understand :(Decrepitate
@eag It's not much more then this to understand, to render a font you need to know where the .ttf is and you need to know what encoding the text is. The devs of the lib to know this information have created font extensions, if you dont provide it they need to start guessing, why it's not working in some cases is because the "guessing" is not correct, but you can not blame the lib for this since they have provided you with a system to avoid the "guessing"Raffarty
H
24

I use IReport to install font:

tools -> options -> fonts -> click install font

Then select the font and click

-> export as extension and type name myfont.jar

add this jar and also spring.jar* to your build path.

*copy spring.jar from Jaspersoft\iReport-3.7.0\ireport\modules\ext

Highup answered 13/7, 2011 at 18:41 Comment(5)
For completion, the arial ttf is in c:/windows/fonts (at least in win xp): arial.ttf, arialbd.ttf(bold),ariali.ttf(italic),arialbi(bold-italic)Bondwoman
Adding spring.jar to the build path fixed it.Antoniettaantonin
This method actually worked for me. It packages the font as a jar file, you add it to the classpath, and things Just Work.Xanthus
If the font-extension is made correctly there is no need to add the spring.jar.Raffarty
This tools->options->fonts->click install is not available on mac. :( any suggestions?Imperturbation
E
16

sudo apt-get install msttcorefonts works (on our Ubuntu development environment), but is not a very good solution.

Instead, we bundled the fonts with our application based on this tip. Their JAR file bundles the following fonts,

  • Arial
  • Times New Roman
  • Courier New
  • Comic Sans MS
  • Georgia
  • Verdana
  • Monospaced

Direct Link to download jar: Maven ver 1.0. DynamicFonts

Epiphyte answered 24/9, 2012 at 3:29 Comment(1)
This can now be downloaded from standard mvn repository, for example: mvnrepository.com/artifact/ar.com.fdvs/DynamicJasper-core-fontsEckblad
P
15

There are three method to avoid such a problem.

Method 1 : by setting ignore missing font property.

JRProperties.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");

or you can set this property by entering following line into .jrxml file.

<property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>

Method 2 : by setting default font property.

JRProperties.setProperty("net.sf.jasperreports.default.font.name", "Sans Serif");

or you can set this property by entering following line into .jrxml file.

<property name="net.sf.jasperreports.default.font.name" value="Sans Serif"/>

Method 3 : by adding missing font property.

Firstly install missing fonts in IReport by selecting " Tools >> Options >> Fonts >> Install Font " then select the all font and Export this By clicking on "Export as Extension" with .jar Extension.

You can use this jar for Jasperreports-font.X.X.X.jar which will be present in your project library or classpath.

Polydactyl answered 5/9, 2015 at 10:54 Comment(0)
K
12

For CentOS:

wget msttcorefonts

Then:

tar -zxvf msttcorefonts.tar.gz
cp msttcorefonts/*.ttf  /usr/share/fonts/TTF/
fc-cache -fv 

After all, restart JVM.

Kelm answered 12/8, 2013 at 13:54 Comment(1)
After using tar -zxvf msttcorefonts.tar.gz I am getting gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now Although the installation was successfulRattray
L
6

I solved this by choosing 'SansSerif' or 'Serif' only and not 'Arial' or 'Times New Roman'.

Lipchitz answered 20/10, 2010 at 11:48 Comment(1)
As per the exception's documention (jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/…), this method is explicitly NOT recommended. It can cause unexpected rendering issues, as these fonts might be mapped to different system fonts on different systems.Scissile
A
5

If you are using maven in your project, you can just add the jasper-fonts dependency to pom.xml:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-fonts</artifactId>
    <version>6.8.1</version>
</dependency>

Installing the missing font on the system may be a working solution but not for me, I didn't want to have to install the missing fonts after each deployment in a new server, instead I opted for embedding the font with the application.

Regards.

Annapurna answered 29/5, 2019 at 17:33 Comment(1)
Does someone know if this dependency will add the "Arial" font?Gitt
D
3

Try adding the line

net.sf.jasperreports.awt.ignore.missing.font=true

to your jasperreports.properties file.

Jasper stops finding one font

Doloresdolorimetry answered 11/7, 2011 at 14:35 Comment(6)
and is a bad idea... export inconsistencies!Raffarty
@PetterFriberg no, it's a good fallback mechanism. You can't always control the JVM. It's ALWAYS a good idea to have a fallback mechanism, even if the result is not ideal it's better than an application crash caused by a missing font on a customer machine.Devitrify
@Devitrify add font-extensions and it will not crash. Trust me if you are disabling you are doing something wrong, you will have incorrect reports generated instead you should solve the root problem (missing font-extensions). And yes you can always control JVM.Raffarty
@Devitrify Do note: The solution is not to install fonts on server (as the accept answer says, it's wrong!). The solution is to generate and add in dependices font-extensions. See this for correct answer stackoverflow.com/a/35549391Raffarty
@PetterFriberg which is often impossible. For example the application I maintain runs on a server, but allows the user to add custom .jrxml files with a specific naming convention in order to generate custom reports above and beyond what we provide as standard. Don't want those reports to crash if the server doesn't have the fonts available that the .jrxml specifies, so we use a fallback.Devitrify
@Devitrify would it not be better that you add some standards fonts in font-extensions and inform user that they should to use those font if they want to ensure correct report generation? or you automatically replace incorrect fonts when jrxml is added? The export inconsistency can be great, text being cut of, letters not visualized (depending on client pc) and you will not conform with PDF/A standards etc. Also the eval function in javascript can be great (let users add code) but is it a good idea?Raffarty
V
3

You can do it by installing fonts, that means everywhere you want to run that particular application. Simplest way is just add this bl line to your jrxml file:

 <property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
Verminous answered 21/5, 2012 at 14:5 Comment(1)
This will however create export inconsistencies (hence it can not render with the font indicated in jrxml). See my answer.Raffarty
N
3

For Debian

add

non-free contrib

to deb and deb-src in /etc/apt/sources.list ie:

deb http://ftp.debian.org/debian/ squeeze main non-free contrib
deb-src http://ftp.debian.org/debian/ squeeze main non-free contrib

Then

apt-get update
apt-get install msttcorefonts

Of course you'll need to restart jasperserver. ie:

/opt/jasperreports-server-cp-4.5.0/ctlscript.sh restart

Change for your version / path.

Needlefish answered 3/8, 2012 at 2:27 Comment(0)
E
3

I faced the issue with my web application based on Spring 3 and deployed on Weblogic 10.3 on Oracle Linux 6. The solution mentioned at the link did not work for me.

I had to take the following steps - 1. Copy the Arial*.ttf font files to JROCKIT_JAVA_HOME/jre/lib/fonts directory 2. Make entries of the fonts in fontconfig.properties.src 3. Restart the cluster from Weblogic console

filename.Arial=Arial.ttf
filename.Arial_Bold=Arial_Bold.ttf
filename.Arial_Italic=Arial_Italic.ttf
filename.Arial_Bold_Italic=Arial_Bold_Italic.ttf
Exudation answered 19/2, 2013 at 18:53 Comment(0)
G
2

can make your custom fonts via iReport and converting like jars files

Gretagretal answered 5/11, 2010 at 0:1 Comment(0)
V
1

Create jasper report in multiple languages(Unicode)

1)Install font in ireport desginer

2)create extension of font(we will use it in applications classpath)

3)install font on os(optional)

4)paste all .ttf of font in jre->lib->fonts directory (otherwise web application will throw error font is not available to JVM)

Vehement answered 10/7, 2014 at 13:37 Comment(0)
A
1

You can use this library which packages the Liberation-fonts as JasperReport font extension, and registers them as Arial, Times New Roman and Courier:

https://mvnrepository.com/artifact/com.mpobjects.jasperreports.font/jasperreports-fonts-liberation

Amadus answered 29/6, 2021 at 10:14 Comment(0)
S
0

Actually I fixed this issue in a very simple way

  1. go to your home path, like /root
  2. create a folder named .fonts
  3. copy your all your font files to .fonts, you can copy the font from C:\windows\fonts if you use windows.
  4. sudo apt-get install fontconfig
  5. fc-cache –fv to rebuid fonts caches.
Shawntashawwal answered 19/1, 2015 at 9:46 Comment(0)
D
0

Solution in 2 steps (if you are using centOS)

  1. Download the Microsoft core fonts rpm package.

    [root@WEBSVR~/]# wget http://www.itzgeek.com/msttcore-fonts-2.0-3.noarch.rpm
    
  2. Install rpm package.

    [root@WEBSVR~/]# rpm -Uvh msttcore-fonts-2.0-3.noarch.rpm
    
Dauntless answered 12/4, 2016 at 8:17 Comment(0)
C
-1

Copy your Fonts on the following directory JDK_HOME\jre\lib\fonts

Cranial answered 28/9, 2010 at 10:46 Comment(0)
T
-1

Hey Having trouble viewing documents produced on Windows?

You can try a fine solution easy:

yum install curl cabextract xorg-x11-font-utils fontconfig

rpm -i https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm

After this I need reboot my system CentOS6.

Source: http://mscorefonts2.sourceforge.net/

Traditor answered 26/4, 2017 at 17:40 Comment(0)
S
-1

Add the below in your .jrxml file:

<property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
Sewan answered 16/6, 2022 at 11:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.