Docbook-to-FO graphics path fix

I rarely write about work, but I am going to make an exception. I’ve had this problem with graphics in my PDFs at work for ages now. The paths are all screwed up, and to fix them, I’ve had to add these crazy relative paths like ../../../../../../../../../graphics/picture.png. And it would work for a while, until I did something like change which machine is building my docs.

I have tried to find a solution online somewhere, and it just doesn’t exist. So I am putting it here in case there is another poor soul out there who has the same problem.  It’s simple really, but it is annoying how long it took to figure out.

This is how I fixed it for Docbook 4.3 and the 1.73.1 XSL stylesheets:

  1. Add the following parameter to your FO parameters file or your command line:
    On your command line it looks like this:
    keep.relative.image.uris 1
    In your FO parameter XSL file, it looks like this:
    <xsl:param name=”keep.relative.image.uris” select=”1″ /xsl:param>
  2. Put your graphics in a directory relative to your FO file when you do your PDF build.
  3. Edit your paths to your graphics so that they are relative to the FO output directory. For example, if all of your graphics are in a directory named /graphics, your graphics path would just be:
    <imagedata fileref=”graphics/my_picture.png” format=”PNG”/>

That’s it. I output my HTML and PDF output into the same directory, so I just put my FO file in there to so when I do the FO->PDF build, the graphics for the HTML file are right there (I use PNG files for both). And now I just feel silly that it took my so long to figure out.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s