Font is not available to the JVM with Jasper Repor

2019-01-01 05:18发布

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?

17条回答
浅入江南
2楼-- · 2019-01-01 06:14

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/

查看更多
公子世无双
3楼-- · 2019-01-01 06:15

Try adding the line

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

to your jasperreports.properties file.

Jasper stops finding one font

查看更多
旧时光的记忆
4楼-- · 2019-01-01 06:18

For CentOS:

wget msttcorefonts

Then:

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

After all, restart JVM.

查看更多
牵手、夕阳
5楼-- · 2019-01-01 06:21

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

查看更多
临风纵饮
6楼-- · 2019-01-01 06:21

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.
查看更多
登录 后发表回答