Font not available to JVM

Help for developers that uses and extend DJ

Moderator: djmamana

Font not available to JVM

Postby rameshraj » 29 Oct 2010, 10:39

I have tried to use Dynamic Japser in my application. Everything seems to work well when the application is deployed in server running under windows machine.
But I need to deploy the application server under unix machine. When I deploy the same application and run under unix machine the font is not available and the following error is diplayed:

net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'VERDANA_MEDIUM' 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:362)
at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:1129)
at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:540)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:329)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:419)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:378)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:440)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:403)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:264)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:946)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:864)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:84)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
at ar.com.fdvs.dj.core.DynamicJasperHelper.generateJasperPrint(DynamicJasperHelper.java:284)
at ar.com.fdvs.dj.core.DynamicJasperHelper.generateJasperPrint(DynamicJasperHelper.java:236)

I have created the following Font instance in my java file:

Font font = new Font(28,"VERDANA_MEDIUM","VERDANA_MEDIUM",Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing,true);
Style titleStyle = new StyleBuilder(false).setFont(font).build();

/**
*Above the font name VERDANA_MEDIUM was used but any of the valid names that can work with default available Fonts under unix machine is highly appreciated
*/
The font is used for different styles in the report that will be generated.

Can any one track the issue and guide me for the fixes or any hints.

Thanks,
Ramesh.
rameshraj
 
Posts: 6
Joined: 29 Oct 2010, 10:25

Re: Font not available to JVM

Postby Nubatar » 01 Nov 2010, 11:34

I had similar problem, which i overcame like this:

I put .ttf file into the application deployment and then in then called something like this:

Font font = new Font(28,"VERDANA_MEDIUM", "c:\app\yourFont.ttf",Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing,true);

if you dont know where the deployment is being made (you dont know the real path to your application) and you are running dynamicJasper from servlet, you can get the right path with something like this:

YourServlet.getRealPath("yourFont.ttf") or YourServlet.getServletPath("yourFont.ttf"), dont know exactly:)

Hope this helps...
Nubatar
 
Posts: 14
Joined: 20 Oct 2010, 10:37

Re: Font not available to JVM

Postby rameshraj » 01 Nov 2010, 11:40

thanks Nubatar,

The scenario you described could have worked well in windows machine. I had the problem in unix machine.

What the problem was that the JVM in the machine could not recognize the font that I specified.
To solve this problem, you should know which Fonts are available in your JVM and use the same font.
To get the available fonts to your JVM do the following:
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
for(String font:e.getAvailableFontFamilyNames()){
System.out.println("Font->"+font);
}
Use one of those fonts in the following line:
Font font = new Font(12,"SansSerif",true);

this solves the problem.
If this doesnot work on weblogic server then you need to add one extra jar file--jasper-compiler-jdt.jar.

I think this will be ok.
I got the problem solved by doing this.

Thanks
rameshraj
 
Posts: 6
Joined: 29 Oct 2010, 10:25

Re: Font not available to JVM

Postby swathi » 10 Feb 2011, 10:41

This can be done by setting a parameter of the dynamic report to false.
DynamicReport dr ;
dr.setProperty(JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, "true");

We faced the same problem with the JVM in the UNIX machine not recognising the fonts. This worked.
swathi
 
Posts: 8
Joined: 07 Dec 2010, 07:02

Re: Font not available to JVM

Postby ngowri » 05 Apr 2011, 05:25

You need to ensure that fonts are available for JRE being invoked. Normally in a linux / unix system, jre (the executable "java" - gij) will be available in /usr/bin (or) /bin directory itself. However, jre will be in /usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre/lib directory. Identify jre being executed (You might need to use "which jre" and "java --version"). Create a fonts/ directory under the ".../lib" directory. Copy all your true type font (*.ttf) files into that /lib/fonts directory.

Stop and start your JRE (assuming this is a application server like tomcat / jboss).
ngowri
 
Posts: 2
Joined: 05 Apr 2011, 05:13


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron