Re: [xsl] Trouble adding an image to FO

Subject: Re: [xsl] Trouble adding an image to FO
From: Tim Meals <tim@xxxxxxxxxxxx>
Date: Tue, 25 May 2004 10:44:38 -0700
Ian --

I would venture it's more of a URL problem than anything else. Try passing in the name of the directory containing the image as a parameter and construct a file URL based on that. Even better -- pass in the URL to the image instead, which would allow you to pull the images from a web server or other location as needed.

<xsl:param name="image-location" select="file:///C|/Temp/Report"/>
[ ... other content goes here ... ]
<fo:external-graphic src="{$image-location}/12345.gif"/>

Tim
--
Tim Meals
Applications Development Consultant
tim@xxxxxxxxxxxx

Ian Lang wrote:

I am using FOP to generate a PDF.  The FO xml is
coming from XSLT.  The trouble is I cannot seem to get
images to show up correctly.  When I prototyped this
from the command line and the xsl, FO and images were
all in the same directory everything was cool but now
that I have moved to code the images cannot be found
by FOP.

Origonally I was producing an FO element like this:
<fo:external-graphic height="10pt" width="10pt"
src="15272099.gif" />


which yielded an error from FOP:
[ERROR] Error while creating area : Error with image
URL: 15272099.gif (The handle is invalid.
) and no base URL is specified

The images, FO and output PDF are still in the same
directory but it is not the current directory from the
command line any more the rendering is being done in
Java code. So I did some experimenting and tried
passing full paths like this:
<fo:external-graphic height="10pt" width="10pt"
src="C:\Temp\Report/8390677.gif" />


which yielded an error from FOP:
[ERROR] Error in XObject : Error while loading image
file:C:/Temp/Report/8390677.gif : class
java.lang.ClassCastException -
java/io/BufferedInputStream incompatible with
java/awt/image/ImageProducer

I also tried file: URL formats which did not help. Then after doing some digging I found reference to an
FO function 'url()'. I tried that with XSL like this:
<xsl:variable name="iconFullPath">
<xsl:value-of select="concat('url(&quot;',
$outputDir, $fileSep, @publish:icon, '&quot;)')"/>
</xsl:variable>
<xsl:message>
<xsl:value-of select="$newLine"/>
<xsl:text>Adding a graphic to the FO XML. The icon
attribute is '</xsl:text>
<xsl:value-of select="@publish:icon"/>
<xsl:text>' and the full uri is '</xsl:text>
<xsl:value-of select="$iconFullPath"/>
<xsl:text>'.</xsl:text>
</xsl:message>


<fo:block font-size="12pt" line-height="15pt"
start-indent="0.5cm">
 <fo:external-graphic width="10pt" height="10pt">
   <xsl:attribute name="src"><xsl:value-of
select="$iconFullPath"/></xsl:attribute>
 </fo:external-graphic>
 <xsl:value-of select="@publish:qualifiedname"/>
</fo:block>

Which creates these FO elements:
<fo:block start-indent="0.5cm" line-height="15pt"
font-size="12pt">
<fo:external-graphic height="10pt" width="10pt"
src="url("C:\Temp\Report/8390677.gif")" /> an.element.qualifed.name </fo:block>


Which produced xsl:message entry:
Adding a graphic to the FO XML.  The icon attribute is
'8390677.gif' and the full uri is
'url("C:\Temp\Report/8390677.gif")'.; SystemID:<snip>

And this error from FOP [ERROR] Error in XObject : Error while loading image
file:C:/Temp/Report/8390677.gif : class
java.lang.ClassCastException -
java/io/BufferedInputStream incompatible with
java/awt/image/ImageProducer


Further digging around the internet yielded no other
ideas.  Any help, inspiration would be appreciated.

Thanks,

IL




__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

Current Thread