Jump to content

PDF Rendering Depends on Server Environment


Recommended Posts

I was about to deploy a nice report I've been working on when I found that it renders differently in my Linux development environment than it does on my local Windows environment.


I can compile it in either environment, it seems to only be different based on which server is generating the PDF.  On Linux:


- Some text fields are cut off on the right edge cutting off 1 or 2 characters. 


- The spacing between rows in the reports is too big.  Is is almost like it is double spacing it instead of the nice tight spacing on Windows.


My first thought was that it is using a different font, but when I save the PDF and view the Document Properties in Acrobat, I see the exact same settings.  I am using the default font that iReport chooses (SansSerif/Helvetica).



I have also tried this in two different Linux environments (Ubuntu/Gnome and Redhat without XWindows) with a straight copy of my whole tomcat install and webapp right off the windows box.  Linux consistently renders poorly.


This is a last minute blocker that is preventing me from using my report.  Very sad.  I have no idea what to do.  Has anyone else experienced this? 



Post Edited by aguth at 05/20/2009 02:00
Link to comment
Share on other sites

  • Replies 16
  • Created
  • Last Reply

Top Posters In This Topic



The answer to this problem you have is found in this FAQ here:



Note that since JR 3.1.3, you can make use of font extensions to make sure you ship the required fonts with your reports so that they are available on the machine you are running on.

Check the samples shipped with JR under the /demo/samples folder, especially the /demo/samples/fonts one.

Also look into the /demo/fonts folder to see what a font extension is made of and how you could package your own font extension.


That font extension there, containing two font families: DejaVu Sans and DejaVu Serif, are shipped with iR, in the form of a JAR file called jasperreports-dejavu-fonts.jar. You'd probably want to create a similar JAR for your fonts.


I hope this helps.



Link to comment
Share on other sites

Thanks so much, I should have seen that in the FAQ.  Anyways, after switching to a TTF font and including it with the appropriate properties files, the PDF's look identical on both platforms.

Link to comment
Share on other sites


I have the same problem and i try to understand the solution delivered in the samples/font  directory.

So i add in the java source directory of my web application the following files:

  1.  the fonts files : arial.ttf and arialnb.ttf.
  2. the fonts.xml files where i define one bean corresponding to my font family :

<bean id="arialFamily" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
  <property name="name" value="TestFontArial"/>
  <property name="normal" value="arial.ttf"/>
  <property name="bold" value="arialbd.ttf"/>
  <property name="pdfEncoding" value="Identity-H"/>
  <property name="pdfEmbedded" value="true"/>

  1. In the java code I add the 2 lines to make the mapping between the logical name

FontKey keya = new FontKey("TestFontArial", false, false);
PdfFont pdfFonta = new PdfFont( "arial.ttf", "Cp1252", false);
fontMap.put(keya, pdfFonta);

  1. In the reports.jrxml, i define a static text as :

<font fontName="TestFontArial" size="10" isBold="false"/>
then i add the jasperreports_extensions.properties .

When i generate on windows or on linux i have still a different pdf document.

could you explain me what is the error i make?

In the example you give, i do not understand why we have to duplicate the mapping between logical font and ttf file , once in the java code and once in the fonts.xml file?

thancks for any information


Link to comment
Share on other sites

I didn't use any font mapping.  I just changed the font name in my .jrxml file.

     <font fontName="DejaVu Sans" size="8" isBold="true"/>
<text><![CDATA[Date & Time]]></text>


Then I put the fonts.xml, jasperreports_extension.properties and all the .ttf files in the WEB-INF/classes folder of my war file. 

And it worked!


Link to comment
Share on other sites


thancks a lot for your answer.

So i have deleted the mapping code  between the font key and the pdffont in my java code.

But it seems that the file fonts.xml is not read (in Windows and in linux) because i have no log info about the loading of beans fonts ?

is there something to do so that the file  jasperreports_extension.properties  is taken into account ?




Link to comment
Share on other sites

I'm not sure what the issue is - I don't do anything special to indicate where the properties file is.  I just put the properties file in the WEB-INF/classes directory, which means it will be found on the classpath.  I think as long as it is on the classpath, it should be found.   I keep fonts.xml in the same spot.  Here is my jasperreports_extension.properties:


I see this line in the console output of my tomcat instance once I generate the first report (but not at webapp start time):

77047 [http-8080-Processor1] INFO xml.XmlBeanDefinitionReader  - Loading XML bean definitions from URL [file:/C:/apache-tomcat/webapps/ReportingApp/WEB-INF/classes/fonts.xml]

Make sure you have spring-beans.jar and spring-core.jar in your lib folder too.






Link to comment
Share on other sites


i finally found what was wrong : in my workspace there was an old version of jasperreports (but not in the classpath!) .

SO the fonts.xml is loaded. But the result is only the same on windows and Linux .

In my fonts.xml, i put 2 beans, one first with mapping relative to arial font , and a second one with a copy of the mapping of the example /fonts (DejaVu sans) 

The result is that the result for text using the second bean is the same on Linux and Windows.

But for text relative to arial family, the result is not the same, and even it seems that the police mapping is not used in the final report.

I fianlly test with only one bean in the fonts.xml , the arial family, and the result is nearly identical : i have a title which appears in local on 3 lines , and on linux only the 2 first lines appears...

But for other static texts the text is no more truncated, that's a good thing! 

Do we have only one bean described in the fonts.xml?




Link to comment
Share on other sites


to conclude on that topic, i would like to have replies from Teodor  about those questions :

1) to export reports to PDF do we always have to  use the solution of describing in a spring file the font in order to be sure to have the same rendering whichever the server environnment is ?

2)  are there any font name that can be used without  this mapping description to export to pdf report?

3) In case we use the spring file to describe more thant one font family, I discovered that only the last  bean is taken into account . Is it a bug?

4) In the solution, we see that the notion of pdfFontname is no more used in jrxml file.   If in ireport3.1.4 we add a static text, by default only the font name attribute is put. Does it mean that the attibute pdfFontName is obsolete?

I really need answers in order to explain to our teams the necessity to migrate to jasper3.1.5 (we use at the present time 3.1.2).









Link to comment
Share on other sites

  • 3 weeks later...


i really need answers to my previous message, specially to the third question : is it possible to declare more than one police font inside fonts.xml? i repeat that in my test it does not work.
We have a projet which at the present time produce pdf file in many languages (european, asian, ...) and so the fonts family can be differents from all those languages.








Link to comment
Share on other sites


i really need answers to my previous message, specially to the third question : is it possible to declare more than one police font inside fonts.xml? i repeat that in my test it does not work.
We have a projet which at the present time produce pdf file in many languages (european, asian, ...) and so the fonts family can be differents from all those languages.

Yes, it's possible.  See the demo/fonts/fonts.xml file in the JR distribution, it shows (the part is commented out though) how to specify fonts per locales.



Link to comment
Share on other sites


thancks Lucian for your last answer.

So for each bean , we have to set a specific locale tag , and the same name value for the property <name> .

I have another question about using asian fonts , as said in the FAQ , to use chinese, japanese fonts, I put the iTextAsian.jar and iTextAsianCmaps.jar on my Web application.

But how can I specify in the file fonts.xml a japanese or chinese font as there are described with .cmap files anf not ttf fonts?






Link to comment
Share on other sites

  • 3 months later...

I am facing a similar issue and have a question about the locales property.

How, specifically, does this property effect PDF generation?


<property name="locales">







is this based on a given locale as input to the exporter?  
Is it possible to handle the case where there can be multiple languages in a generated report, say english and chinese.
In my case, our app is given a locale, but that represents the locale of the person generating the report, not the settings of the data itself.
Ideally there would be one font that could handle all languages, or at least many of them [unicode].
Link to comment
Share on other sites

  • 1 month later...
  • 13 years later...

Hello, the link pointing to a solution on this is no longer available. Me and my team have been having the same issues regarding cut Chinese characters which do not appear in some columns but not others when line break or page break. We've tried everything and when it seems like it is solved, when we go try it on a different environment, the behaviour is different and the problem is not solved. Sometimes white spaces completely disappear along with part of the content too. I cannot follow the link to Teodor's answer as it is no longer available. Any help?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...