JasperReports 5.6: Could not load the following font
Solution 1
The problem was the template itself: At one font-tag the <fontName>
property was missing:
Does not work:
<font size="12" isBold="true" pdfFontName="Arial"/>
Does work:
<font fontName="Arial" size="12" isBold="true" pdfFontName="Arial" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
Solution 2
Copy the fonts files (*.ttf) into the folder:
/path/to/app/WEB-INF/classes/***HERE***
You app will get the fonts from here :)
Solution 3
You must give the correct name of font for the PDF exporter. Your fonts are presents into the embedded fonts jar. You don't need to put them again into the classes directory ;-)
There is the correct fonts.xml content for pdf exporter (perhaps the names are case sensitive, be careful) :
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="Arial">
<normal>
<ttf>fonts/Arial/ARIAL.TTF</ttf>
<pdf>fonts/Arial/ARIAL.TTF</pdf>
</normal>
<bold>
<ttf>fonts/Arial/ARIALBD.TTF</ttf>
<pdf>fonts/Arial/ARIALBD.TTF</pdf>
</bold>
<italic>
<ttf>fonts/Arial/ARIALI.TTF</ttf>
<pdf>fonts/Arial/ARIALI.TTF</pdf>
</italic>
<boldItalic>
<ttf>fonts/Arial/ARIALBI.TTF</ttf>
<pdf>fonts/Arial/ARIALBI.TTF</pdf>
</boldItalic>
<pdfEncoding>Cp1252</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
</exportFonts>
</fontFamily>
</fontFamilies>
I hope this help.
Regards, T.
Tunguska
Updated on December 13, 2020Comments
-
Tunguska over 3 years
I am facing the problem, that JasperReports still cannot find the Arial font.
I created a simple Maven Project with following structure and included it to my main application. So the main application contains the installed JAR in classpath:
- jasperreports_extension.properties - fonts |-> arial |-> ariali.ttf |-> arialbi.ttf |-> arialbd.ttf |-> arial.ttf |-> fonts.xml
But I still see following Exception while exporting report to PDF.
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : Arial pdfEncoding : Identity-H isPdfEmbedded : true
jasperreports_extension.properties
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory net.sf.jasperreports.extension.simple.font.families.arial=fonts/fonts.xml
fonts.xml:
<?xml version="1.0" encoding="UTF-8"?> <fontFamilies> <fontFamily name="Arial"> <normal>fonts/arial/arial.ttf</normal> <bold>fonts/arial/arialbd.ttf</bold> <italic>fonts/arial/ariali.ttf</italic> <boldItalic>fonts/arial/arialbi.ttf</boldItalic> <pdfEncoding>Identity-H</pdfEncoding> <pdfEmbedded>true</pdfEmbedded> </fontFamily> </fontFamilies>
Template
<font fontName="Arial" size="8" pdfFontName="Arial" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
-
Gustavo over 8 yearsI don't get. I have the same problem but only on Linux. On Windows it works fine, so, I don't think the problem is the template, but the loading of the extension.
-
Alfabravo about 8 years@Gustavo oddly enough, it's happening to me on Windows, not on Linux. Running out of things to try...