freemarker 图片输出、多张图片输出(图片重复原因及解决)

来源:http://www.cnblogs.com/dreammyle/p/4631351.html

单张图片显示:

  先写好word格式的文档,在其中插入一张图片,然后重命名为ftl,再用编辑器打开,把图片那一段base64信息用freemarker表达式替换掉。 之后把图片的信息输出到模板即可。

多张图片显示:

  需要注意的是,多张图片显示时,当list循环的时候,如果你不改变图片两个属性w:name和imagedata src的值,那么它永远也是调用第一张图片的地址,显示的都是第一张图片。

更改两个属性w:name和 imagedata  src的方法:

  用变量个体的索引来改变两个属性的名字,变量个体的索引格式为“变量名字_index”,见下面红色加粗字体部分。

复制代码
<#list images as im><w:pict>    <v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">        <v:stroke joinstyle="miter"/>        <v:formulas>            <v:f eqn="if lineDrawn pixelLineWidth 0"/>            <v:f eqn="sum @0 1 0"/>            <v:f eqn="sum 0 0 @1"/>            <v:f eqn="prod @2 1 2"/>            <v:f eqn="prod @3 21600 pixelWidth"/>            <v:f eqn="prod @3 21600 pixelHeight"/>            <v:f eqn="sum @0 0 1"/>            <v:f eqn="prod @6 1 2"/>            <v:f eqn="prod @7 21600 pixelWidth"/>            <v:f eqn="sum @8 21600 0"/>            <v:f eqn="prod @7 21600 pixelHeight"/>            <v:f eqn="sum @10 21600 0"/>        </v:formulas>        <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>        <o:lock v:ext="edit" aspectratio="t"/>    </v:shapetype>    <w:binData w:name="${"wordml://0200000"+im_index+1+".jpg"}" xml:space="preserve">        ${im}    </w:binData>    <v:shape id="图片" o:spid="_x0000_i1025" type="#_x0000_t75" style="width:414.75pt;height:207.75pt;visibility:visible;mso-wrap-style:square">        <v:imagedata src="${"wordml://0200000"+im_index+1+".jpg"}" o:title="菜单"/>    </v:shape></w:pict></#list>

猜你喜欢

转载自blog.csdn.net/rentian1/article/details/80399135