Keywords: Jasper Reports | Font Unavailable | JRFontNotFoundException | Font Extension | Ubuntu | JVM Font
Abstract: This article provides a comprehensive analysis of JRFontNotFoundException errors in Jasper Reports, specifically focusing on 'Arial' and 'DejaVu Sans' font unavailability issues in Ubuntu systems. Through multiple solutions including system installation of ttf-mscorefonts-installer package, Jasper Reports font extensions, and configuration of font ignore options, it explores the impact of font availability on report generation. With detailed code examples and configuration steps, the article offers a complete resolution path from temporary fixes to best practices, helping developers thoroughly address cross-platform font compatibility challenges.
Problem Background and Error Analysis
When generating reports with DynamicJasper, developers frequently encounter the net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'Arial' is not available to the JVM error. This indicates that the JVM cannot locate the font specified in the report template, causing report generation to fail.
Jasper Reports employs a strict font verification mechanism to ensure consistent rendering across different environments. When a font defined in the report is unavailable to the JVM, the system throws JRFontNotFoundException as a protective measure against layout issues caused by font metric mismatches.
System Font Installation Solution
In Ubuntu systems, the most direct solution involves installing the Microsoft core fonts package. Here are the complete installation steps:
sudo apt-get update
sudo apt-get install --reinstall ttf-mscorefonts-installer
Ensure stable internet connectivity during installation and accept the EULA (End User License Agreement) when prompted. After installation, verify successful font installation using:
ls /usr/share/fonts/truetype/msttcorefonts/
If installation is successful, this directory should contain font files like Arial and Times New Roman, not just the README file.
Font Extension Mechanism Explained
While system font installation can resolve the issue, Jasper Reports officially recommends using the font extension mechanism. This approach packages font files into JAR files, ensuring font availability in any deployment environment.
Jasper Reports provides a default font extension JAR file jasperreports-fonts-x.x.x.jar containing DejaVu Sans, DejaVu Serif, and DejaVu Sans Mono fonts. Usage example:
<font fontName="DejaVu Sans"/>
Creating custom font extensions involves selecting font files, exporting them as JAR files using JasperSoft Studio or iReport tools, and adding the generated JAR files to project dependencies.
Temporary Solutions and Risks
In urgent situations, developers may choose to disable the font verification mechanism:
System.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
Or configure in JasperReports properties file:
<property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
However, this approach carries significant risks, potentially causing inconsistent rendering across different devices, especially with complex layouts and text wrapping.
Cross-Platform Compatibility Considerations
The different behavior of DejaVu Sans font between Java 8 and Java 11, as mentioned in reference articles, highlights the complexity of font compatibility. Even with font extensions, issues may arise in Java 8 environments due to differences in JVM font rendering mechanisms.
Solutions include ensuring the use of the latest Jasper Reports font extensions, testing rendering effects across different JVM versions, and considering more universal font families.
Best Practices Summary
Based on analysis of multiple solutions, the following best practices are recommended:
- Use font extension mechanisms during development to avoid system font dependencies
- Ensure font extension JAR files are properly included in application dependencies for production deployment
- For multilingual support, choose fonts with complete Unicode character sets
- Regularly test report rendering across different operating systems and JVM versions
- Consider using pre-packaged font JAR files provided by DynamicJasper
By following these practices, Jasper Reports can generate correctly across various environments, avoiding runtime errors caused by font unavailability.