Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font is not available to jvm while converting a report from jrxml to pdf

I am using eclipse in windows.

I am getting this error while generating pdf file from jrxml file using jar jasperreports-4.1.1.jar. I have manually added font files in my jre from my windows folder and have added font path to path variable but still getting the same error.

net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : 
pdfFontName   : Arial
pdfEncoding   : Cp1252
isPdfEmbedded : false

Another weird thing which I have observed is that when I try the same function for Cambria font, I get a different error. Below is the error when I use cambria

net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'CAMBRIA' is not available to the JVM. See the Javadoc for more details.
at net.sf.jasperreports.engine.util.JRFontUtil.checkAwtFont(JRFontUtil.java:358)
at net.sf.jasperreports.engine.util.JRStyledText.getAwtAttributedString(JRStyledText.java:226)
at net.sf.jasperreports.engine.export.AbstractTextRenderer.render(AbstractTextRenderer.java:263)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportText(JRPdfExporter.java:2026)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:729)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportFrame(JRPdfExporter.java:2526)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:733)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportFrame(JRPdfExporter.java:2526)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:733)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:689)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:582)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:376)
at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:122)
at main.CopyOfTable.runReport(CopyOfTable.java:60)
at main.CopyOfTable.main(CopyOfTable.java:100)
like image 858
user1859459 Avatar asked Nov 28 '12 10:11

user1859459


1 Answers

Hope this helps:

  1. Define your fonts as "font extensions". This involves creating two files: jasperreports_extension.properties and fonts.xml. See how it's done in the demo/fonts directory in the JasperReports package you can download from http://community.jaspersoft.com/project/jasperreports-library/releases.

  2. Package your fonts and the font extensions into a JAR file that is available on the classpath.

This works for TrueType and OpenType fonts.

Also:

See Teodor's first comment here.

One of many helpful answers on this site is here.

Good luck.

like image 60
glenn380 Avatar answered Sep 25 '22 16:09

glenn380