我使用Apache POI使用WordToFoConverter类将.doc转换为.fo,我已将word文件中的图像转换为base64,但如何将其附加到apache-poi生成的xsl-fo代码中?
考虑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>
如何在 * 位置插入图像?
答案 0 :(得分:13)
直接插入图像,base64编码在&#34; src&#34;属性,注意标记适当的mimetype ...例如对于JPEG图像:
<fo:external-graphic src="url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA....')"/>
这是一个可以帮助您理解结构的模板:
<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>