利用freemarker技術,填充word模板(插入圖片)

此處做簡要說明:

   在模板中添加圖片佔位,另存時候,將圖片的base64編碼全部刪除,附上變量。替換的時候注意圖片轉碼問題,其他地方不變。

   

private String getImageStr(String imgFile) {
        InputStream in = null;
        byte[] data = null;
        try {
            in = new FileInputStream(imgFile);
            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(data);
    }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章