Forum How do I...?

Reference Images in background-image: urls?

I'm trying to use the same css stylesheet for a webpage and for a pdf file generated by princexml.

For the webpage I have my path specified from the document root, i.e.

background-image: url(/images/header.jpg);

Using this with Prince XML shows a file not found error in the error log.

However this works as expected:

background-image: url(/absolute/path/to/document/root/images/header.jpg);

I'm not able to change the contents of the css file, it has to stay as per the first example. Is there any way to prepend a path to image filepaths when prince renders the PDF? I thought baseURL might do it, but it hasn't helped.

Thanks in advance for your help,

We need to add a new command-line option for this, eg. --basedir instead of --baseurl. In the meantime, an easy workaround would be to run Prince on the HTTP URL instead of the local file, then all the paths will resolve correctly.
Thanks for the help. That work-around can't really be applied in this situation as the page we're rendering is in the admin section of our site and there are various security levels it would have to go through before accessing the html output via http.

As a work around, we're doing a simple find and replace on the paths and saving the css in temporary files to load specifically for the PDFs. This is an ugly solution, but its the simplest thing that will work. We'd definitely change it around to use basedir once that feature is implemented. Any idea on an ETA for it?
I'll move it up the roadmap and see if we can get it ready for Prince 7.1.
In Prince 7.1 we have added an experimental new command-line option called --fileroot, which allows you to specify a path that will be used to resolve absolute filenames.