I have read through the sample code included in 3.6.1 (demo/samples/fonts).
I modified my jasperreports.properties file to include:
However, when I run my existing reports, attempting to generate PDF, I get:
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'BlairITC TT' is not available to the JVM. See the Javadoc for more details. at net.sf.jasperreports.engine.util.JRStyledText.getAwtAttributedString(JRStyledText.java:228)
I am not currently using the Spring framework, and would rather not have to deal with that. Is my only option to now programatically create an instance of 'SimpleFontFamily', and set all of the propeties (name, normal, italic, pdfEncoding, pdfEmbedded, etc.) on that object. Then add the object to the JRFiller?
Is there an example showing that approach instead? I was really hoping this would be as simple as specifying the directory of my TrueType fonts...
Here is one fix that I have tried, but which did not work:
JRProperties.setProperty("net.sf.jasperreports.export.pdf.fontdir.jasper", "/home/jason/svn/trunk/lib/fonts/"); JRProperties.setProperty("net.sf.jasperreports.export.pdf.font.BlairITC TT.Normal","/home/jason/svn/trunk/lib/fonts/BlairMdITCTTMedium.ttf"); JasperExportManager.exportReportToPdfStream(pFilledReport, pOut);
The exception I am still getting is:
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'BlairITC TT' is not available to the JVM. See the Javadoc for more details. at net.sf.jasperreports.engine.util.JRStyledText.getAwtAttributedString(JRStyledText.java:228) at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:353) at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:1003) at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:542)
This exception was introduced in JR 3.6.1 so that is more obvious to our users that they are creating reports using fonts that are not available on the machines that run those reports.
Very many problems that are reported on these forums are related to misuse of fonts in reports.
You get this error because you are using fontName="BlairITC TT" in your reports and this particular font is not available to the JVM that renders your report.
You have two options here:
1. configure JR to ingnore missing fonts and continue using what is basically an invalid report template, which is missing an important resource: the font.
You can do this by setting the net.sf.jasperreports.awt.ignore.missing.font=true in the jasperreports.properties file or as a custom property in that particular report template.
Note that this is not recomended as unpredictable results will be obtained when the JVM will use some other font to calculate your report layout.
2. Package the TTF files that make up the BlairTC TT font into a JAR that represents a JR font extension and add it to your application classpath. This will make the font available to the JVM and thus the report will work properly on all machines.
The easiest way to do so is to rely on a few Spring JARs and package your fonts the same way we did with the DejaVu fonts that we ship under the /demo/fonts sample. Note the fonts.xml file in the folder hierachy. If you don't want to use Spring, you would need to implement some JR extensions interfaces. You could do so by looking into the implementations that are already shipped as part of JR, and follow the Javadoc.
Note that exception is related to fonts being used with AWT, at report fill time and they do not have to do with PDF. What you have tried are some PDF-related settings that are nowadays deprecated, as PDF font mappings are done in the font extensions as well.
The easiest way to create font extensions is by using iReport 3.6.1, which comes with a TTF install wizard and a font export tool, in the Tools/Options/iReport/Fonts menu.
I hope this helps.
After a day spent walking through the Jasper source in the debugger, I finally found the critical error.
I had modified my jasperreports_extensions.properties file to contain a reference to the factory and my fonts.xml file (trying to replicate the appraoch taken in the 'Fonts' sample code). In my first attempt, the resulting file after ant variable substitution looked like this:
NOTE: The pathname to the 'fonts.xml' file is a full pathname. This version resulted in none of my custom font declarations being found by or made available to the JVM.
On a whim, I then modified the location of the fonts.xml file and the reference to it so that both would end up in the same directory after compliation (/home/jason/svn/trunk/classes), and to use the following relative path to the fonts.xml file:
This had the desired effect - it caused the SpringExtensionsRegistry to load, parse, and process my fonts.xml file. In that file, I then defined fonts such as, where the ant macro @CLASSES@ is expanded at compile time to the complete canonical path to the TTF file. The use of the full pathname in this file did not have any negative side effect. However, at some point I will reformulate this to use a relative pathname.:
<bean id="blairITCFontFamily" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily"> <property name="name" value="BlairITC TT"/> <property name="normal" value="@CLASSES@/BlairMdITCTTMedium.ttf"/> <property name="bold" value="@CLASSES@/BlairITCTTBold.ttf"/> <property name="pdfEncoding" value="Identity-H"/> <property name="pdfEmbedded" value="true"/> <property name="exportFonts"> <map> <entry key="net.sf.jasperreports.html"> <value>Arial, Helvetica, sans-serif</value> </entry> <entry key="net.sf.jasperreports.xhtml"> <value>Arial, Helvetica, sans-serif</value> </entry> </map> </property> </bean>
So everything is now back to normal :)
I don't understand why you work with absolute file locations on disk.
The path to the fonts.xml file should be its path within classpath, not path on disk.
This is why I told you font extensions are packaged in JAR. If you use absolute file names, packaging the font extension in a JAR does not make any sense anymore.
thank you for the JAR-tip in iReport.
I just want to add a bug report:
The jasperreports_extension.properties in the generated JAR-file has a wrong path to the fonts**.xml in the sub-directory "fonts".
It references the XML-file with a beginning Slahs (/fonts/fonts**.xml) which is wrong, I had to manualy remove this slash or it will end in an exception when starting JBoss and Jasper is creating its registries.
I am new to Jasper Reports and have to upgrade an existing implementation from 3.5.2 to 3.6.2.
After doing the upgrade, some of our existing reports now fail with the JRFontNotFoundException as described in this thread.
I can avoid the exception by setting the ...ignore.missing.font=true as described above. As far as I understand, this will restore the previous behavior ... where no checking was done. However, I would rather fix it "properly" if possible.
As far as I know, my report definitions make no (intentional) effort to use any specific or custom fonts whatsoever. When I get the exception, it refers to the "sansserif" font e.g.
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'sansserif' is not available to the JVM. See the Javadoc for more details.
I get this problem both in iReport and when running the report through my application.
Should I be seeing this problem for this font? Or does it indicate something else wrong.
Unfortunately I'm not very up on the whole area of fonts and Jasper in general ... just trying to upgrade to the latest version without doing any damage ... so any comments/explanations would be most welcome.
The easiest "fix" you could do would be to use "SansSerif". In the past, the default value for fontName was not correct in iR/JR.
But if you want a more solid fix, then I suggest you replace everywhere you have fontName="SOME_SANS_FONT" with fontName="DejaVu Sans" and everywhere you have fontName='SOME_SERIF_FONT" with fontName="DejaVu Serif".
You also remove everywhere the pdfFontName, pdfEncoding and isPdfEmbedded, as these are now deprecated and dealt with in the font extension JARs.
You then add the jasperreports-fonts-xxx.jar file to the classpath of your application, because it contains a font extension that provides the above mentioned DejaVu fonts. You can download this font JAR from the same location where you find the JasperReports JAR or project ZIP, at Sourceforge.net.
You would have to give your reports a sanity check again, to see if all texts appear OK, paying special attention to static texts which might have a height that is too small for the new fonts to render properly. In such cases, you either need to increase the height a bit or reduce font size.
If you never played with fonts before, it means you did not generate reports in other languages than English or you did not export to PDF. Because if you did, then you must have used some TTF fonts that support the particular language you used in those reports.
I hope this helps.
Everything works fine on my developer system since there seem to be all fonts installed on that Windows box. The customer runs a SuSE Linux Enterprise server and I ran into the discussed problem after upgrading to 3.6.2.
The quick hack with net.sf.jasperreports.awt.ignore.missing.font=true succeeded but I am interested in a real solution because I have space problems due to missing fonts.
I packed a JAR with Arial TTFs and also tried the jar with the DejaVu font from sourceforge. Unfortunately I get an exception when one of the font jars is within the classpath:
javax.ejb.EJBException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser; nested exception is: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser java.lang.RuntimeException: java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:174) at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
Without the font jars everything works fine. I read this indicates that different library versions are used. I did a grep in my jboss installation but there is version 3.6.2 installed only.
I think the exception must have a cause down the stack trace. I suspect it is about the Spring jars missing.
The font extension is a Spring-based extension and needs those extra JARs that you can find in the /lib directory of the JR project distribution package.
I hope this helps. Teodor
can it be that "exportFonts" attribute is no longer available in SimpleFontFamily in 3.6.2? If not, the example (fonts.xml) should be modified to not include that.
Furthermore i have a severe problem with the font jar extension mechanism when trying to load OTF fonts.
To my knowledge this should work from java perspective.
System: Java6 on Mac OS X.
Post Edited by loge at 12/15/2009 22:10
got a small qn
ive already designed some 40 odd reports with the 'pdffontname' attribute and removing that from every report becomes cumbersome.. is there any way that these reports would run fine(with desired fonts) on a linux server just by adding the font extensions jar to the appn classpath
I trying to generate at report with a ttf font, but also get the JRFontNotFoundException.
I trying to use the DejaVu Sans font.
I using Java EE 6 on Glassfish 3.0. iReport 3.7.1, JasperReport 3.7.1
<font fontName="DejaVu Sans" isUnderline="false" isPdfEmbedded="true"/>
I used Tools/Options/iReport/Fonts to import and "export as extension"
I generate jasperreports-fonts-DejaVu Sans.jar and I put in WEB-INF\\lib
The jasperreports-fonts-DejaVu Sans.jar contains:
- fonts - DejaVuSans.ttf - fonts1273221481231.xml - jasperreports_extension.properties
<?xml version="1.0" encoding="UTF-8"?>
<bean id="fontBean127322148123753178" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
<property name="name" value="DejaVu Sans"/>
<property name="normal" value="fonts/DejaVuSans.ttf"/>
<property name="pdfEmbedded" value="true"/>
For bold font in PDF, you need to use a bold TTF font. Check again your font extension (if you use one) and make sure that for bold font you specify a TTF that is really bold. Otherwise, the engine will use the same TTF as for the normal/regular font, hence the problem.
Same thing for italic and bold/italic.
Note that in case you don't have a special bold font file to use, the boldness can be simulated in PDF.
But all this works only if you use fonts from a font extension. Check the samples under /demo/samples in the JR distro and especially the font extension that we ship with the project under /demo/fonts.
iReport has a wizard to create font extension JARs, to deploy with your reports.
I hope this helps.
I've read all the postings on this subject.
I have generated my Arial.jar file which contains the arial.ttf family fonts. This jar along with the jasperreports-3.7.3, spring-2.5 jars are located on my WAS classpath. When I attempt to generate a report, I get the following exception:
[1894435 --- 12628]2011-02-24 13:39:06,914] [DEBUG]: - Instantiating extensions registry class net.sf.jasperreports.extensions.DefaultExtensionsRegistry [1894435 --- 12628]2011-02-24 13:39:06,920] [DEBUG]: - Loading registries for cache key sun.misc.Launcher$AppClassLoader@755f755f [1894435 --- 12628]2011-02-24 13:39:06,922] [DEBUG]: - Found resource jasperreports_extension.properties at jar:file:/opt/was61/AppServer/profiles/Appsrv01/installedApps/cvgrheespd002Node01Cell/ESpecApp.ear/jasperreports-3.7.3.jar!/jasperreports_extension.properties in classloader sun.misc.Launcher$AppClassLoader@755f755f [1894435 --- 12628]2011-02-24 13:39:06,923] [DEBUG]: - Found resource jasperreports_extension.properties at jar:file:/opt/was61/AppServer/profiles/Appsrv01/installedApps/cvgrheespd002Node01Cell/ESpecApp.ear/Arial.jar!/jasperreports_extension.properties in classloader sun.misc.Launcher$AppClassLoader@755f755f [1894435 --- 12628]2011-02-24 13:39:06,924] [DEBUG]: - Loading JasperReports extension properties resource jar:file:/opt/was61/AppServer/profiles/Appsrv01/installedApps/cvgrheespd002Node01Cell/ESpecApp.ear/jasperreports-3.7.3.jar!/jasperreports_extension.properties [1894435 --- 12628]2011-02-24 13:39:06,926] [DEBUG]: - Instantiating registry of type net.sf.jasperreports.extensions.DefaultExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.default [1894435 --- 12628]2011-02-24 13:39:06,926] [DEBUG]: - Instantiating extensions registry for default using factory class net.sf.jasperreports.extensions.DefaultExtensionsRegistryFactory [1894435 --- 12628]2011-02-24 13:39:06,927] [DEBUG]: - Instantiating registry of type net.sf.jasperreports.governors.GovernorExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.governor [1894435 --- 12628]2011-02-24 13:39:06,927] [DEBUG]: - Instantiating extensions registry for governor using factory class net.sf.jasperreports.governors.GovernorExtensionsRegistryFactory [1894435 --- 12628]2011-02-24 13:39:06,928] [DEBUG]: - Instantiating registry of type net.sf.jasperreports.components.ComponentsExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.components [1894435 --- 12628]2011-02-24 13:39:06,928] [DEBUG]: - Instantiating extensions registry for components using factory class net.sf.jasperreports.components.ComponentsExtensionsRegistryFactory [1894435 --- 12628]2011-02-24 13:39:06,951] [DEBUG]: - Loading JasperReports extension properties resource jar:file:/opt/was61/AppServer/profiles/Appsrv01/installedApps/cvgrheespd002Node01Cell/ESpecApp.ear/Arial.jar!/jasperreports_extension.properties [1894435 --- 12628]2011-02-24 13:39:06,952] [DEBUG]: - Instantiating registry of type net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.fonts [1894435 --- 12628]2011-02-24 13:39:06,952] [DEBUG]: - Instantiating extensions registry for fonts using factory class net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory [1894435 --- 12628]2011-02-24 13:39:07,009] [ERROR]: - Error instantiating extensions registry for fonts net.sf.jasperreports.engine.JRRuntimeException: Could not find Spring resource /fonts/fonts1298566395082.xml for extensions registry fonts at net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory.getBeanFactory(SpringExtensionsRegistryFactory.java:91) at net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory.createRegistry(SpringExtensionsRegistryFactory.java:73) at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instantiateRegistry(DefaultExtensionsRegistry.java:238) at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:213) at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:162) at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRegistries(DefaultExtensionsRegistry.java:132) at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:104) at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:76) at java.lang.J9VMInternals.initializeImpl(Native Method) at java.lang.J9VMInternals.initialize(J9VMInternals.java:194) at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:181) at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:76) at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:86) at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:56) at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:78) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624) at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:513) at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:465) at com.acnielsen.espec.bo.util.ExportDataToReportUtility.generateShellValuesReport(ExportDataToReportUtility.java:465) at com.acnielsen.espec.bo.util.ExportDataToReportUtility.generateJasperReport(ExportDataToReportUtility.java:137) at com.acnielsen.espec.bo.reports.ReportsBO.getReportsBO(ReportsBO.java:109) at com.acnielsen.espec.bo.reports.ScheduleLaterService.generateReportNow(ScheduleLaterService.java:434) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:618) at com.acnielsen.espec.bo.reports.ScheduleLaterService.run(ScheduleLaterService.java:195) at com.acnielsen.standalone.main.ESpecReportsMain.main(ESpecReportsMain.java:51)
Any assistance would be greatly appreciated.
I've attached my Arial.jar file for reference.
Thank you Sanda for the help...that was the issue.
The new exception is:
[1894492 --- 8036]2011-02-25 11:49:08,367] [ERROR]: - No input source supplied to the exporter. com.acnielsen.arch.exception.arch.ACNException: No input source supplied to the exporter. at com.acnielsen.espec.bo.util.ExportDataToReportUtility.exportAsExcel(ExportDataToReportUtility.java:235) at com.acnielsen.espec.bo.util.ExportDataToReportUtility.generateJasperReport(ExportDataToReportUtility.java:138) at com.acnielsen.espec.bo.reports.ReportsBO.getReportsBO(ReportsBO.java:109) at com.acnielsen.espec.bo.reports.ScheduleLaterService.generateReportNow(ScheduleLaterService.java:434) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:618) at com.acnielsen.espec.bo.reports.ScheduleLaterService.run(ScheduleLaterService.java:195) at com.acnielsen.standalone.main.ESpecReportsMain.main(ESpecReportsMain.java:51) Caused by: net.sf.jasperreports.engine.JRException: No input source supplied to the exporter. at net.sf.jasperreports.engine.JRAbstractExporter.setInput(JRAbstractExporter.java:845) at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:169) at com.acnielsen.espec.bo.util.ExportDataToReportUtility.exportAsExcel(ExportDataToReportUtility.java:227) ... 9 more
This report worked perfectly fine prior to the upgrade.
I've figured out what the issue with the no input source found.
The offending code is trying to set the PROPERTY_WRAP_TEXT, boolean.FALSE.
the code is as follows:new JExcelApiExporter();
JExcelApiExporter xlsExporter =
xlsExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());new HashMap();if (jasperPrint.getName().equalsIgnoreCase("DroppedUpc") || jasperPrint.getName().equalsIgnoreCase("InstructionSummary"))"65000"));
As soon as the HashMap (m) is set to the parameters, all the previously set parameters are wiped out. Can someone give me some direction on how to set the PROPERTY_WRAP_TEXT properly? Any help is greatly appreciated. Thank you.
Can someone help me understand the subject of PROPERTY_TEXT_WRAP? I'm seeing that when the data populated in the cell is larger than the cell width, the text is wrapped. Simply put, if the column definition is 50 and the data returned to the cell is 100, the text will wrap. Even if I put the property_text_wrap.False, the text still wraps.
Does anyone have any idea how to prevent text from wrapping?
Any assistance would be greatly appreciated!
Even I am using Sans Sarif or DejaVu Sans, I am getting exception for Times Roman, I didn't use Times Roman anywhere in my report. Coul you please advise how do I fix this problem? I am using iReport/Jasperreport 4.1.1 and jdk 7
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'Times-Roman' 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.fill.TextMeasurer.measure(TextMeasurer.java:326) at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:510) at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:593) at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:328)