How to configure Apache FOP to use JIMI/JAI for PNG support?

Here should go questions about transforming XML with XSLT and FOP.
okleven
Posts: 4
Joined: Mon May 30, 2011 7:36 pm
Location: France

How to configure Apache FOP to use JIMI/JAI for PNG support?

Post by okleven »

Hi,
I need to display a logo using my FO customization layer, but after specifying the PNG file in the xsl, I (of course) get this error:

ERROR - Image not available. URI: . Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for....

I guess this is as expected, since the oXygen manual (I'm on version 12.2) has a section about how to install PNG support with the JIMI/JAI libraries. I have read that section thoroughly, and I have downloaded and installed the JIMI and JAI libraries. I have added them to both the classpath and my Windows PATH as instructed. I also copied the libraries to [Oxygen-install-dir]\lib just in case. But I still get the same error, so there must be more to this than just these libraries being installed.

The manual claims that "Using them is as easy as downloading them and creating a external FO processor". This does not seem easy at all to me. Installing the libraries, yes, but creating an external FO processor, no. I have no clue how to configure a complicated command line like the one shown in the example there. I have tried to figure out how to do this in the Preferences, by selecting "Use other Apache FOP", but don't know where to go from there, or how to configure Apache FOP or any other FOP. It's not intuitive at all to me.

I hope someone has some tips on how to actually do this...

Thanks,
Oystein
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: How to configure Apache FOP to use JIMI/JAI for PNG support?

Post by adrian »

Hello,

Actually that section of the manual is a bit outdated.

Have you tried processing this PNG file with an image tool(e.g. GIMP)?
Maybe the file is corrupt or in a format other than PNG(the file extension can be deceiving).

The PNG image format is supported out-of-the-box in the Java SE Runtime Environment and in Apache FOP 1.0 that comes bundled with Oxygen 12.2. So there should be no need for JAI or JIMI to handle a simple PNG file.
http://xmlgraphics.apache.org/fop/1.0/graphics.html

Anyway, if you really want to deploy JAI and JIMI and want to avoid headaches with paths and classpaths:
1. Install JAI in the JRE folder. Oxygen's JRE is located in OxygenInstallationFolder/jre/.
2. Put the JimiProClasses.zip in the folder OxygenInstallationFolder/jre/lib/endorsed/. Create the endorsed folder if it was missing.

After restarting Oxygen, running a transformation that uses the Apache FOP should pick both JAI and JIMI libraries.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
okleven
Posts: 4
Joined: Mon May 30, 2011 7:36 pm
Location: France

Re: How to configure Apache FOP to use JIMI/JAI for PNG support?

Post by okleven »

Hi Adrian,
Thanks for your reply. I did as you said, but it still doesn't work, no matter where I put these libraries. And no, I don't want to use JIMI or JAI if I can avoid it, I prefer built-in support. So with this new info from you I began to think there was something else wrong.

After a lot of trial and error, I found out that the real problem was that FOP actually couldn't find the file, as it gave the same error no matter which valid or invalid (non-existent) file I specified.

I got the template from Bob Stayton's book. He mentions that the call to the "fo-external-image" is necessary to parse the filename correctly, so I looked at lot at that. The solution didn't make too much sense to me since the parsing template is there, but the way I specify the file name makes the difference (with single quotes and full path).

Works: select="'file:/C:\<full path>\logo-header-small.png'"

Doesn't work: select="logo-header-small.png"
(the image file is in the same dir as the stylesheet)

In this template call:
<xsl:call-template name="fo-external-image">
<xsl:with-param name="filename" select="'file:/C:\<full path>\logo-header-small.png'"/>
</xsl:call-template>

And you are right, this works both with or without the JIMI and JAI stuff, so I removed them and stick with the built-in support.

Problem solved. Thanks for your help.

Regards,
Oystein
Post Reply