freeMarker多图片生成

freeMarker多图片生成

  • 图片地址转换为base64位
  • freemarker代码块
  • 注意事项:<v:imagedat r:id={} >中的对应的是第二个代码块中
  • 第二代码块中的 对应的是第三代码块中的 <pkg:part pkg:name={} >
  • 一个对应不上则显示数据错误
 /**
     * 将网络图片编码为base64
     *
     * @return
     * @throws
     */
    public static String factoryBase(String StoragePath) {
        try {
            URL url = new URL(StoragePath);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setConnectTimeout(5 * 1000);
            InputStream inStream = conn.getInputStream();
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = inStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, len);
            }
            inStream.close();
            byte[] data = outStream.toByteArray();
            BASE64Encoder encoder = new BASE64Encoder();
            String base64 = encoder.encode(data);
            return base64;
        } catch (Exception e) {
            return "";
        }
    }
<#if insectionData?exists>
                        <w:p>
                            <w:pPr>
                                <w:widowControl/>
                                <w:adjustRightInd/>
                                <w:jc w:val="center"/>
                                <w:textAlignment w:val="auto"/>
                                <w:rPr>
                                    <w:rFonts w:hint="default" w:ascii="Times New Roman" w:hAnsi="Times New Roman"
                                              w:cs="Times New Roman"/>
                                    <w:kern w:val="0"/>
                                    <w:sz w:val="24"/>
                                    <w:szCs w:val="24"/>
                                </w:rPr>
                            </w:pPr>
                            <#list insectionData as insectionData>
                                <#if insectionData.imgPath??>
                                    <#list insectionData.imgPaths as im>
                                        <#if im??>
                                            <w:r>
                                                <w:rPr>
                                                    <w:rFonts w:hint="eastAsia" w:ascii="Times New Roman" w:hAnsi="Times New Roman"
                                                              w:cs="Times New Roman"/>
                                                    <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                                </w:rPr>
                                                <w:pict>
                                                    <v:shape id="_x0000_i1025" o:spt="75" alt="微信图片_20220510150724" type="#_x0000_t75"
                                                             style="height:185pt;width:185pt;" filled="f" o:preferrelative="t"
                                                             stroked="f" coordsize="21600,21600">
                                                        <v:path/>
                                                        <v:fill on="f" focussize="0,0"/>
                                                        <v:stroke on="f"/>
                                                        <v:imagedata r:id="${"rId2"+im_index+10+""}" o:title="微信图片_20220510150724"/>
                                                        <o:lock v:ext="edit" aspectratio="t"/>
                                                        <w10:wrap type="none"/>
                                                        <w10:anchorlock/>
                                                    </v:shape>
                                                </w:pict>
                                            </w:r>
                                        </#if>
                                    </#list>
                                </#if>
                            </#list>

                        </w:p>
                    </#if>
<#list insectionData as insectionData>
                    <#if insectionData.imgPath??>
                        <#list insectionData.imgPaths as im>
                            <#if im??>
                                <Relationship Id="${"rId2"+im_index+10+""}"
                                              Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
                                              Target="${"media/image2"+im_index+".jpg"}"/>
                            </#if>
                        </#list>
                    </#if>
                </#list>
<#if insectionData?exists>
        <#list insectionData as insectionData>
            <#if insectionData.imgPath??>
                <#list insectionData.imgPaths as im>
                    <#if im??>
                        <pkg:part pkg:name="${"/word/media/image2"+im_index+".jpg"}" pkg:contentType="image/jpg">
                            <pkg:binaryData>${im}
                            </pkg:binaryData>
                        </pkg:part>
                    </#if>
                </#list>
            </#if>
        </#list>
    </#if>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值