14

I have MIME Multi-Part data that I want to convert to PDF using XSL:FO. I'm comfortable reading MIME using Apache James and I have a grasp on embedded image data in Mime or inline images in HTML. I diligently searched SO for "[xsl-fo] inline graphic" and "[xsl] +html +mime +image" and found somehow the opposite and a precurser what I'm up to. Also Google on "convert HTML MIME to XSL:FO" was inconclusive.

What I want to do is having an element (or a set of elements) that render a graphic (JPG/PNG/GIF - all or some of them) in the PDF output of an XSL:FO transformation. The graphic data should be included inside the .fo file as Base64 (or otherwise) encoded data. I found how to point to external graphics, but nothing about embedded graphic data.

How would that work?

Community
  • 1
  • 1
stwissel
  • 20,110
  • 6
  • 54
  • 101

1 Answers1

32

The element fo:external-graphic can be utilized to embed inline data as well. Just use the following syntax:

<fo:external-graphic src="url('data:image/jpeg;base64,<DATA>')"/>

<DATA> should be replaced with your base64 data string of the JPEG image.

Martin
  • 1,748
  • 1
  • 16
  • 15
  • @Martin, can you point to some reference documentation where this is explained? According to the XSL specification, the value of the `src` attribute should be a "uri-specification" (`src=url(...)`). – mzjn May 04 '12 at 10:56
  • 1
    @mzjn: You're right. I should have wrapped the `src`value with `url()` to be compliant with the standard. Since I primarily use FOP which accepts the shorthand form, I didn't thought about the explicit `url()` construct. I'll edit the answer accordingly. – Martin May 04 '12 at 11:48
  • @Martin for this I get "Image not found. URI: data:image/png;base64,iVBORw0K...". Any idea? – maybesomename Apr 19 '23 at 19:38