Jasper Reports 的 JVM 无法使用字体

发布于 2024-09-25 16:30:55 字数 399 浏览 9 评论 0 原文

我正在尝试使用 DynamicJasper 生成报告,但收到以下错误:

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

msttcorefonts 已安装,但我猜 JVM 没有使用其中的任何字体。

我使用的是 Ubuntu 10.04。

我该如何解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

秋风の叶未落 2024-10-02 16:30:55

我尝试安装 mscorefonts,但该软件包已安装并且是最新的。

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

我尝试在文件系统中搜索字体,其中:

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

此文件夹只有自述文件,以及有关如何安装的正确说明。

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

为此,您需要互联网连接:

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

我重新安装了 ttf-mscorefonts-installer(如上所示,确保接受 EULA!),问题得到解决。

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.

悍妇囚夫 2024-10-02 16:30:55

如果 JVM 无法将报表模板中使用的字体作为系统字体或来自 JR 字体扩展的字体使用,则 JasperReports 会引发 JRFontNotFoundException。这可确保避免由字体规格不匹配引起的所有问题,并且我们可以对不一致发出早期警告。

Jasper reports 试图在报告开发中帮助您,但指出它无法正确导出您的报告,因为它找不到 TextFieldStaticText 中定义的字体

<font fontName="Arial"/>

是的,您可以通过设置 net.sf.jasperreports.awt.ignore.missing.font 为 true,但您会遇到导出不一致的情况。

是的,您可以安装该字体作为 JVM 系统字体(但您需要在可能生成报告的每台使用的 PC 上执行此操作,并且您仍然可能遇到编码问题)。

正确的方法!

如果您想创建自己的字体,请使用字体扩展自己的(请参见下面的链接),jasper reports 还分发了一个默认的字体扩展 jar (jasperreports-fonts-xxxjar),支持 fontName DejaVu SansDejaVu Serif DejaVu Sans Mono

<font fontName="DejaVu Sans"/>

来自 JasperReport 终极指南:

我们强烈鼓励人们仅使用源自字体的字体
扩展名,因为这是确保字体的唯一方法
当报告执行时,应用程序将可以使用
运行时。使用系统字体总是会带来报告不正确的风险
当部署在可能没有的新机器上时可以正常工作
那些安装的字体

StackOverflow 上有关如何在 pdf 中正确渲染字体的链接

有关如何在 pdf 中正确渲染字体的清单

使用 JasperSoft Studio 生成字体扩展

生成字体-iReport 扩展

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

热风软妹 2024-10-02 16:30:55

我使用 IReport 安装字体:

工具->选项->字体->点击安装字体

然后选择字体并单击

->导出为扩展名并输入名称 myfont.jar

将此 jar 和 spring.jar* 添加到您的构建路径。

*从 Jaspersoft\iReport-3.7.0\ireport\modules\ext 复制 spring.jar

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

思念满溢 2024-10-02 16:30:55

sudo apt-get install msttcorefonts 可以工作(在我们的 Ubuntu 开发环境上),但不是一个很好的解决方案。

相反,我们根据此技巧将字体与我们的应用程序捆绑在一起 。他们的 JAR 文件捆绑了以下字体,

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

直接链接下载 jar:
Maven 版本 1.0。动态字体

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

不知所踪 2024-10-02 16:30:55

有三种方法可以避免此类问题。

方法 1:通过设置忽略缺少字体属性。

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

或者您可以通过在 .jrxml 文件中输入以下行来设置此属性。

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

方法 2:通过设置默认字体属性。

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

或者您可以通过在 .jrxml 文件中输入以下行来设置此属性。

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

方法3:通过添加缺少的字体属性。

首先通过选择“工具>>选项>>字体>>安装字体”在IReport中安装缺少的字体,然后选择所有字体并导出通过单击带有 .jar 扩展名的“导出为扩展名”。

您可以将此 jar 用于 Jasperreports-font.XXXjar,它将出现在您的项目库或类路径中。

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.

葬花如无物 2024-10-02 16:30:55

对于 CentOS:

wget msttcorefonts

然后:

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

毕竟,重新启动 JVM。

For CentOS:

wget msttcorefonts

Then:

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

After all, restart JVM.

扭转时空 2024-10-02 16:30:55

我通过仅选择“SansSerif”或“Serif”而不是“Arial”或“Times New Roman”解决了这个问题。

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

夏雨凉 2024-10-02 16:30:55

如果您在项目中使用 maven,则只需将 jasper-fonts 依赖项添加到 pom.xml:

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

在系统上安装缺少的字体可能是一个可行的解决方案,但不适合我,我不想安装每次在新服务器中部署后都缺少字体,而是选择将字体嵌入到应用程序中。

问候。

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.

始终不够爱げ你 2024-10-02 16:30:55

行添加

尝试将net.sf.jasperreports.awt.ignore.missing.font=true

到 jasperreports.properties 文件中。

Jasper 停止查找一种字体

Try adding the line

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

to your jasperreports.properties file.

Jasper stops finding one font

太阳哥哥 2024-10-02 16:30:55

对于 Debian,

在 /etc/apt/sources.list 中添加

non-free contrib

deb 和 deb-src 即:

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

然后

apt-get update
apt-get install msttcorefonts

当然你需要重新启动 jasperserver。即:

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

更改您的版本/路径。

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.

与酒说心事 2024-10-02 16:30:55

我的 Web 应用程序基于 Spring 3 并部署在 Oracle Linux 6 上的 Weblogic 10.3 上,遇到了这个问题。 链接 对我不起作用。

我必须采取以下步骤 -
1. 将 Arial*.ttf 字体文件复制到 JROCKIT_JAVA_HOME/jre/lib/fonts 目录
2. 在 fontconfig.properties.src 中输入字体
3. 从Weblogic控制台重新启动集群

filename.Arial=Arial.ttf
filename.Arial_Bold=Arial_Bold.ttf
filename.Arial_Italic=Arial_Italic.ttf
filename.Arial_Bold_Italic=Arial_Bold_Italic.ttf

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
双马尾 2024-10-02 16:30:55

您可以通过安装字体来做到这一点,这意味着您想要在任何地方运行该特定应用程序。最简单的方法就是将此 bl 行添加到 jrxml 文件中:

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

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"/>
内心旳酸楚 2024-10-02 16:30:55

可以通过 iReport 制作自定义字体并像 jar 文件一样进行转换

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

听风吹 2024-10-02 16:30:55

以多种语言(Unicode)创建jasper报告

1)在ireport设计器中安装字体

2)创建字体扩展(我们将在应用程序类路径中使用它)

3)在操作系统上安装字体(可选)

4)粘贴jre->lib->fonts 目录中所有 .ttf 字体(否则 Web 应用程序将抛出错误 font is not available to JVM)

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)

草莓酥 2024-10-02 16:30:55

您可以使用此库,它将 Liberation-fonts 打包为 JasperReport 字体扩展,并将它们注册为 Arial、Times New Roman 和 Courier:

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

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

清浅ˋ旧时光 2024-10-02 16:30:55

实际上,我用一种非常简单的方法解决了这个问题,

  1. 转到您的主路径,例如/root
  2. 创建一个名为的文件夹.fonts
  3. 将您的所有字体文件复制到.fonts,您可以从C:\windows\fonts<复制字体/code> 如果你使用 Windows。
  4. sudo apt-get install fontconfig
  5. fc-cache –fv 重建字体缓存。

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.
懵少女 2024-10-02 16:30:55

两步解决方案(如果您使用的是centOS)

  1. 下载Microsoft核心字体rpm包。

    [root@WEBSVR~/]# wget http://www.itzgeek.com/msttcore-fonts-2.0-3.noarch.rpm
    
  2. 安装rpm包。

    [root@WEBSVR~/]# rpm -Uvh msttcore-fonts-2.0-3.noarch.rpm
    

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
    
圈圈圆圆圈圈 2024-10-02 16:30:55

将您的字体复制到以下目录中
JDK_HOME\jre\lib\字体

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

微凉徒眸意 2024-10-02 16:30:55

嘿,查看 Windows 上生成的文档时遇到问题?

您可以轻松尝试一个很好的解决方案:

百胜安装curl cabextract xorg-x11-font-utils fontconfig

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

之后我需要重新启动我的系统 CentOS6。

来源:http://mscorefonts2.sourceforge.net/

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/

傲性难收 2024-10-02 16:30:55

我有同样的问题,当我在 jasperreports 中运行时没有问题,但是当我在 JAVA 中使用 exportReportToPdf 运行它时,它崩溃并出现字体未找到错误。
我的解决方案是,在我的报告中,我有一个带有标记样式的静态文本(静态文本中嵌入了 html)。
我的标签中有两个属性:“fontName”和“pdfFontName”
解决方案是退出这两个属性,从这个:

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

到这个:

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

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....
心在旅行 2024-10-02 16:30:55

在您的 .jrxml 文件中添加以下内容:

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

Add the below in your .jrxml file:

<property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文