Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a base64 encoded image into xsl-fo file while using apache-poi

I am using Apache POI to convert .doc to .fo using the WordToFoConverter class, I have converted the images in the word file to base64, but how do i append it to the xsl-fo code generated by apache-poi?

Consider the sample fo file generated by Apache-POI-

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="page-page0" page-height="11.0in" page-width="8.5in">
<fo:region-body margin="1.0in 1.0in 1.0in 1.0in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:declarations>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="">
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">CA, Inc.</dc:creator>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
</fo:declarations>
<fo:page-sequence master-reference="page-page0">
<fo:flow flow-name="xsl-region-body">
<fo:block hyphenate="true" linefeed-treatment="preserve" space-after="10pt" text-align="start" white-space-collapse="false">
***<!--Image link to '0.jpg' can be here-->
<fo:inline font-family="Times New Roman" font-size="11" font-style="normal" font-weight="normal">               </fo:inline>
<!--Image link to '9ab33.png' can be here-->
<fo:leader/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>

How do i insert an image at the * position?

like image 380
user3683297 Avatar asked Jun 03 '14 11:06

user3683297


1 Answers

insert the image directly, base64 encoded in the "src" attribute, taking care to mark the appropriate mimetype ... for example for JPEG image:

<fo:external-graphic src="url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA....')"/>

Here's a template that can help you understand the structure:

 <xsl:template match="encodedImage">
    <fo:external-graphic>
        <xsl:attribute name="src">
            <xsl:text>url('data:</xsl:text>
            <xsl:value-of select="attachmentContentType"/>                
            <xsl:text>;base64,</xsl:text>
            <xsl:value-of select="encodedImageBytes"/>
            <xsl:text>')</xsl:text>
        </xsl:attribute>
    </fo:external-graphic>
</xsl:template>
like image 63
Kevin Brown Avatar answered Sep 22 '22 00:09

Kevin Brown