113

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?

7
  • 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
    Commented Sep 30, 2010 at 9:27
  • You would need to install microsoft fonts in Ubuntu, refer this link for information .. embraceubuntu.com/2005/09/09/installing-microsoft-fonts Commented Feb 9, 2011 at 7:08
  • 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
    Commented Aug 14, 2013 at 21:33
  • 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. Commented Feb 22, 2016 at 8:58
  • 1
    jasperreports-fonts-6.8.0 adding this jar worked for me.
    – vdeshan
    Commented Jun 1, 2019 at 2:34

21 Answers 21

78

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.

11
  • 5
    FYI on other linux flavours try sudo apt-get install msttcorefonts
    – KCD
    Commented Feb 14, 2012 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
    Commented Aug 14, 2013 at 21:33
  • What about the most common windows OS?
    – Sarz
    Commented Dec 9, 2015 at 6:02
  • 2
    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 Commented Feb 22, 2016 at 8:59
  • 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 Commented Nov 8, 2016 at 22:04
48

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

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) Commented May 31, 2017 at 6: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. Commented May 31, 2017 at 7: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 :( Commented Jun 1, 2017 at 0: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" Commented Jun 1, 2017 at 6:36
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

5
  • 1
    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)
    – jneira
    Commented Nov 17, 2011 at 7:59
  • Adding spring.jar to the build path fixed it.
    – fishjd
    Commented Sep 21, 2012 at 21:36
  • This method actually worked for me. It packages the font as a jar file, you add it to the classpath, and things Just Work.
    – Satya
    Commented Jul 1, 2013 at 17:40
  • 1
    If the font-extension is made correctly there is no need to add the spring.jar. Commented Feb 22, 2016 at 9:00
  • This tools->options->fonts->click install is not available on mac. :( any suggestions?
    – L-Samuels
    Commented Oct 14, 2016 at 12:34
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

1
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.

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.

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 successful Commented Mar 1, 2022 at 7:06
6

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

1
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.

1
  • Does someone know if this dependency will add the "Arial" font?
    – midi
    Commented Dec 16, 2022 at 11:19
3

Try adding the line

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

to your jasperreports.properties file.

Jasper stops finding one font

6
  • 2
    and is a bad idea... export inconsistencies! Commented Feb 22, 2016 at 9: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
    Commented Sep 19, 2019 at 6: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. Commented Sep 19, 2019 at 6: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 stackoverflow.com/a/35549391 Commented Sep 19, 2019 at 6: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
    Commented Sep 19, 2019 at 6:38
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.

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
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"/>
1
  • 2
    This will however create export inconsistencies (hence it can not render with the font indicated in jrxml). See my answer. Commented Feb 22, 2016 at 9:01
2

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

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)

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

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.
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
    
0

I have the same issue , when I run in jasperreports no problem, but when i run this in JAVA with the exportReportToPdf, it crashes with the font not found error. My solution was that in my report I have a static text with markup style (html embedded in the static text). And I have two attributes in the tags: "fontName" and "pdfFontName" The solution was quit this two attributes, from this:

<style markup = "style" fontName="PTSansNarrow-Bold.ttf" pdfFontName="PTSansNarrow-Bold.ttf" isPdfEmbedded...

To this:

<style markup = "style" isPdfEmbedded="true" isBold....
-1

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

-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/

-1

Add the below in your .jrxml file:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.