Thursday, June 22, 2006

xsl:fo dynamically insert external image.

We were trying to insert a dynamically generated image in our PDF document generated using apache FOP. Reading the documentation on their site it was clear that you can insert an external image by specifying the URL to that image. However, it wasn't quite clear how I could dynamically generate this image URL.
We needed this badly as we wanted to insert scanned signature images (which of course were not public URLs :).
The end goal in our case was to generate something like this:

<fo:external-graphic src="url('file:d:///images/toms_signature.jpg')"/>

when tom is logged in, and

<fo:external-graphic src="url('file:d:///images/teenas_signature.jpg')"/>

when teena is logged in.
After much googling, we found the solution. Simply put, you can extract your image URL from the XML. I'm assuming you know how to dynamically generate it in the XML (duh!). Here's how:

We changed the XML to generate a <signatureImage> element as follows:


Then we added the following element in our XSL:FO in the correct place (the place in the document where the signature was to be displayed).

<xsl:template match="document">


<fo:external-graphic src="{signatureImage}"/>


</xsl:template match="document">

That's it! It works like a charm!!

Gosh Neeraj!! I didnt know you speak a language I dont even know the name of!! Saw your blog link on Ketaki's and thought of looking at it! Your blog looks........hmmmm......well... Hebrew...! Pardon my ignorance!!!
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?