使用 apache-poi 时将 base64 编码的图像插入到 xsl-fo 文件中 [英] Inserting a base64 encoded image into xsl-fo file while using apache-poi

查看:27
本文介绍了使用 apache-poi 时将 base64 编码的图像插入到 xsl-fo 文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache POI 使用 WordToFoConverter 类将 .doc 转换为 .fo,我已将 word 文件中的图像转换为 base64,但如何将其附加到 apache-poi 生成的 xsl-fo 代码中?

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?

考虑 Apache-POI- 生成的示例 fo 文件

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>

如何在*位置插入图片?

推荐答案

直接插入图像,base64 编码在src"属性中,注意标记适当的 mimetype ... 例如对于 JPEG 图像:

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>

这篇关于使用 apache-poi 时将 base64 编码的图像插入到 xsl-fo 文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆