103

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?

bruno
  • 2,213
  • 1
  • 19
  • 31
Andrew
  • 2,663
  • 6
  • 28
  • 50
  • 3
    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.... – Andrew Sep 30 '10 at 09:27
  • 1
    where do you set this? i'm working with an embedded version of jasperreports in jbilling where no jasperreports.properties file exists to edit. – Darragh Aug 14 '13 at 21:33
  • http://stackoverflow.com/questions/19978524/jasper-report-font-error Refer it – Jaichander Mar 22 '14 at 13:40
  • 1
    @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. – Petter Friberg Feb 22 '16 at 08:58
  • You would need to install microsoft fonts in Ubuntu, refer this link for information .. http://embraceubuntu.com/2005/09/09/installing-microsoft-fonts/ – Sivaramakrishnan Feb 09 '11 at 07:08
  • use this :- https://community.jaspersoft.com/wiki/custom-font-font-extension – Dusman Apr 04 '18 at 07:01
  • 1
    jasperreports-fonts-6.8.0 adding this jar worked for me. – vdeshan Jun 01 '19 at 02:34

20 Answers20

76

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.

hichris123
  • 10,145
  • 15
  • 56
  • 70
Braully Rocha
  • 1,364
  • 2
  • 16
  • 22
  • 5
    FYI on other linux flavours try sudo apt-get install msttcorefonts – KCD Feb 14 '12 at 23:52
  • 1
    for CentOS and RHEL6 how do you solve the EULA problem? yum install doesn't give you any option to accept, any ideas? – Darragh Aug 14 '13 at 21:33
  • What about the most common windows OS? – Sarz Dec 09 '15 at 06:02
  • 1
    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 answer – Petter Friberg Feb 22 '16 at 08:59
  • 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 candidate – arvindwill May 07 '16 at 04:14
  • 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 candidate – arvindwill May 07 '16 at 04:14
  • For Cloud VM http://askubuntu.com/questions/659305/package-ttf-mscorefonts-installer-has-no-installation-candidate – arvindwill May 07 '16 at 04:19
  • 1
    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-installer – Aleksander Lech Nov 08 '16 at 22:04
  • How to do it on `Amazone Linux`? – Asif Sep 28 '21 at 13:47
  • For it to take effect I had to reboot the machine after installing the fonts. – Diego Portillo Jul 05 '23 at 13:36
41

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

default locale
  • 13,035
  • 13
  • 56
  • 62
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • 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) – EagerToLearn May 31 '17 at 06:00
  • 1
    @EagerToLearn 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. – Petter Friberg May 31 '17 at 07:02
  • 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 :( – EagerToLearn Jun 01 '17 at 00:13
  • @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" – Petter Friberg Jun 01 '17 at 06:36
23

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

LQPQueue
  • 15
  • 4
juan
  • 231
  • 2
  • 3
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

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
user799188
  • 13,965
  • 5
  • 35
  • 37
  • This can now be downloaded from standard mvn repository, for example: https://mvnrepository.com/artifact/ar.com.fdvs/DynamicJasper-core-fonts – Markus Pscheidt Apr 18 '18 at 10:34
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.

Mayur Bhokase
  • 377
  • 4
  • 19
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.

Ricardo Carmo
  • 643
  • 5
  • 6
  • 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 successful – Eatsam ul haq Mar 01 '22 at 07:06
6

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

lkdg
  • 1,031
  • 7
  • 18
  • 6
    As per the exception's documention (http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/util/JRFontNotFoundException.html), 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. – Doug Mar 27 '14 at 18:11
4

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"/>
Kenly
  • 24,317
  • 7
  • 44
  • 60
Punky
  • 97
  • 1
  • 12
  • 2
    This will however create export inconsistencies (hence it can not render with the font indicated in jrxml). See my answer. – Petter Friberg Feb 22 '16 at 09:01
4

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.

Yassir Khaldi
  • 1,452
  • 1
  • 17
  • 30
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.

d-_-b
  • 6,555
  • 5
  • 40
  • 58
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
Ujjwal
  • 603
  • 12
  • 23
3

Try adding the line

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

to your jasperreports.properties file.

Jasper stops finding one font

Community
  • 1
  • 1
  • 2
    and is a bad idea... export inconsistencies! – Petter Friberg Feb 22 '16 at 09:02
  • 1
    @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. – jwenting Sep 19 '19 at 06:14
  • @jwenting 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. – Petter Friberg Sep 19 '19 at 06:17
  • @jwenting **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 https://stackoverflow.com/a/35549391 – Petter Friberg Sep 19 '19 at 06:22
  • @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. – jwenting Sep 19 '19 at 06:38
  • @jwenting 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? – Petter Friberg Sep 19 '19 at 06:47
2

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

mavirroco
  • 117
  • 10
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)

rushabh
  • 31
  • 1
  • 3
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

yglodt
  • 13,807
  • 14
  • 91
  • 127
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.
Saorikido
  • 2,173
  • 2
  • 26
  • 37
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
    
BSMP
  • 4,596
  • 8
  • 33
  • 44
Venkat Prasanna
  • 692
  • 4
  • 16
0

Add the below in your .jrxml file:

<property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
-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/

Fernando Pie
  • 895
  • 1
  • 12
  • 28
-1

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

Ahmad Zyoud
  • 3,474
  • 1
  • 14
  • 4