PDF is rendering differently on differend servers?

Hi,

Our J2EE software is based on Spring Framework and we use the Jasper Reports as reporting tool.

All the reports (single paged PDF-forms) have been designed by using Ireport.

However I have problem with Jasper Reports PDF rendering. The PDFs are rendered perfectly when the application is run on Tomcat (on Windows). The problems starts when I install the application on Oracle 10g (on AIX UNIX). The problem is that the PDF looks a bit differend. Biggest difference is the space between lines + some other. When the space between the rows is larger than on the original, the text doesn't fit to the text field on the report form.

One solution is ofcourse to enlarge the text fields, but on every situation it's not possible.

Does anybody have any idea why these PDFs renders differently?
noon's picture
117
Joined: Aug 10 2006 - 4:53am
Last seen: 17 years 1 month ago

8 Answers:

Hi,

Those rendering differences are caused by missing fonts on the AIX machine.
If for instance you have used fontName="Arial", it works perfect on Windows, but on AIX, since Arial does not exists, some other default font is used, with different font metrics, hence the various side effects.
The recommended way to deal with fonts on crossplatform applications is to make sure you rely on some TTF files that you ship with your application and install them on-the-fly using the Font.createFont() method.
You would also be referencing thos TTF files in the pdfFontName attribute in JRXML.

I hope this helps.
Teodor
teodord's picture
53502
Joined: Jun 30 2006 - 9:00am
Last seen: 1 hour 51 min ago
Thanks Teodor for replying. I'll try what you suggested. I'll post again if I managed to find a proper solution.
noon's picture
117
Joined: Aug 10 2006 - 4:53am
Last seen: 17 years 1 month ago
Hello all,

I'm having exactly the same problem in AIX, and I do have the TTF files embedded in the report. Has the above suggested solution worked?

Thanks

mal
maldoror's picture
107
Joined: Jul 28 2007 - 11:55pm
Last seen: 16 years 2 months ago

Hi Teodor,

 

Can you please elaborate this issue and give some sample code for resolving this issue?

forhitesh's picture
1129
Joined: May 2 2007 - 5:32pm
Last seen: 16 years 5 months ago

Hi

I also met with this problem. My problem was like yours.

The problem was the report i viewed on windows/tomcat server behaves different on linux/oracle app. server.

And i found the reason of this problem was the fonts that i used in my report. The font u selected in design time should be available on linux machine. And jvm must know this fonts. For example if you use Arial your report behaves different. Becasue Arial doesnt exists on linux.  For solution u can try these

1-) Choose a font which already exists on linux for fontName attribute for every fieled in report. (For example Lucida Bright)

2-) Make available the font you used  for linux.

 



Post Edited by bulut bulut at 01/23/09 15:31
bulut's picture
364
Joined: Jan 8 2009 - 7:47am
Last seen: 14 years 8 months ago

Hi,

    I have solved this problem using a method like the one posted in this reply. fontmap is a static HashMap in the class used later in the PDF exporter in this way:

            pdfexporter.setParameter(JRExporterParameter.FONT_MAP,
                    FontRegister.fontMap);

    FontRegister is the class that contains the registerFont method.

    Take in consideration that this method needs java 1.6 due to the use of "registerFont"  method to dinamically register the font.

     If you report design contain in the pdfFontName attribute a value like "font.ttf" the font.ttf must be placed in the webapp classpath: WEB-INF/lib or WEB-INF/classes (just place de fonts in the root, not in subfolders).

      If the weapp have a a custom font dir you must indicar in the pdfFontName (again, if the value is a ttf font file) the full path to this font. i.e: /home/user/fonts/arial.ttf

      Hope this helps someone. Forgive my bad english (is not my native language as you can read).

 

 

 

 

 

  

 

   

 

 

 

 

Code:
    private boolean registerFont(String fontsdir, String fontfile) {
 
        FileInputStream fis = null;
        boolean retval = false;
        String fullfontpath = fontsdir + File.separator + fontfile;
        FontKey key;
        PdfFont font;
 
        try {
 
            _log.info(sessionid +"registering in AWT");
            fis = new FileInputStream(fullfontpath);
            Font customFont = Font.createFont(Font.TRUETYPE_FONT, fis);
            ge.registerFont(customFont);
 
            _log.info(sessionid +"registering en iText");
            FontFactory.register(fullfontpath);
 
            _log.info(sessionid + "se logro registrar la tipografia <" +
                customFont.getFontName() + "> correspondiente a la familia <" +
                customFont.getFamily() + ">");
 
            /** 
             * actualizamos el parametro FONT_MAP que luego utilizara la clase
             * ReportExporter al exportar el reporte al formato PDF.
             */
            key = new FontKey(customFont.getFontName(), false, false);
            font = new PdfFont(fullfontpath, "Cp1252", true);
            fontMap.put(key, font);
 
            retval = true;
        } catch (FontFormatException ex) {
            _log.error(sessionid + "se produjo un error al registrar la " +
                    "tipografia <" + ex + ">");
            ex.printStackTrace();
        } catch (IOException ex) {
            _log.error(sessionid + "se produjo un error de E/S <" + ex + ">");
            ex.printStackTrace();
        } catch (Exception e) {
            _log.error(sessionid + "se produjo un error generico <" + e + ">");
            e.printStackTrace();
        } finally {
            try {
                fis.close();
            } catch (IOException ex) {
                _log.error(sessionid + "se produjo un error al cerrar el " +
                        "inputstream de la tipografia <" + ex + ">");
                ex.printStackTrace();
            }
        }
        return retval;
    }</td></tr></tbody></table>
pablodc's picture
823
Joined: Jul 4 2007 - 4:59am
Last seen: 16 years 3 months ago

Hi Teodor,

 

How is pdfFontName supposed to relate to the registered font name?

This is just not quite working - or making sense yet.  When running on Linux, I can't get the fonts to register, but even when I do, how do I refer to them in the JRXML?

First, I get this exception which I can find exactly NO WHERE on the Internet:

ExceptionConverter: com.lowagie.text.DocumentException: Table 'name' does not exist in /home/tomcat/webapps/ourproject/WEB-INF/classes/arial.ttf

 

When it can't find or load the font it gets:
 loadFont exception: ExceptionConverter: com.lowagie.text.DocumentException: Table 'name' does not exist in /home/tomcat/webapps/kcpt/WEB-INF/classes/arial.ttf

The "loadFont exception" comes from the code:

            loadFont(gfp+"arial.ttf","arial.ttf");
            loadFont(gfp+"ariali.ttf","ariali.ttf");
            loadFont(gfp+"arialbd.ttf","arialbd.ttf");
            loadFont(gfp+"arialbi.ttf","arialbi.ttf");

    public boolean loadFont(String fontLocation, String fontName) {
        boolean ret=false;
        try {
            FontFactory.register(fontLocation, fontName);
            ret=true;
        } catch (Exception de) {
            logger.warn(" loadFont exception: ", de);
        }
        return ret;
    }

I am running in Tomcat on Linux.  And the font f iles are there in the classes directory:  arial.ttf, arialbd.ttf, and araili.ttf and arialbi.ttf

 

Second about the pdfFontName.   I refer to these in the JRXML as pdfFontName=  what?

What I tried is:

          <staticText>
                <reportElement x="12" y="24" width="550" height="21"/>
                <textElement textAlignment="Center">
                    <font fontName="Arial" size="11" isBold="true" isUnderline="true" pdfFontName="arialbd.ttf"/>
                </textElement>
                <text><![CDATA[II. CRITICAL FUNCTIONS]]></text>
            </staticText>

That FAILS -- completely.


So, I went back to:

           <staticText>
                <reportElement x="12" y="24" width="550" height="21"/>
                <textElement textAlignment="Center">
                    <font fontName="Arial" size="11" isBold="true" isUnderline="true" pdfFontName="Helvetica-Bold"/>
                </textElement>
                <text><![CDATA[II. CRITICAL FUNCTIONS]]></text>
            </staticText>

This gets some other font (probably because it can't find the font its trying to register). 

Many thanks


Regards,

 

Richard Katz

richkatz's picture
362
Joined: Jul 27 2009 - 10:56am
Last seen: 14 years 2 months ago
Hi,

I want to generate one simple Jasper Report using Spring Framework 3.0
I am using Glassfish 2.1 as my webserver and its a web application rendering the report.
The application generates report but its a blank pdf or blank html page.

Can you help me?

Thanks in Advance
asgdemo's picture
100
Joined: Jul 26 2010 - 10:19pm
Last seen: 13 years 2 months ago
Feedback
randomness