Search code examples
xsl-foapache-fop

Adding images from memory to Apache FOP PDF


I'm interesting in using Apache FOP to write PDFs. However, all the images I will have will be in memory. I'm new to XML/XSL-FO and not sure how I would reference an image in memory rather than one specified by filename on disk, if that's even possible. All the examples I see on Apache FOP's website seem to reference images on disk.

I see you can use all sorts of methods to load the XSL-FO document in, and the image library seems robust. But no mention of how you would reference an image in memory (say a BufferedImage) in that XSL-FO document.


Solution

  • In memory, convert the image to a known format and inject a base 64 encoded image directly into the XSL FO using a data URL scheme. As in ...

    src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...".

    Unclear this works with FOP, never used it, work with most other XSL FO engines as well as web browsers.