# word2pdf **Repository Path**: frozend/word2pdf ## Basic Information - **Project Name**: word2pdf - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-03-17 - **Last Updated**: 2022-03-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 简介 > 样例仅供参考,大家可以自行修改和开发 > 如有疑问,可联系开发者 - developer: - @author Alpha - @Date 2022/03/17 - @email dhwalj1314@163.com - 此项目作用: - word 替换模版变量 - word 转pdf - 项目依赖: ```xml org.apache.poi poi-ooxml 4.1.0 org.apache.poi poi-ooxml-schemas 4.1.0 org.apache.poi poi-scratchpad 4.1.0 org.apache.poi poi 4.1.0 fr.opensagres.xdocreport fr.opensagres.poi.xwpf.converter.pdf-gae 2.0.2 org.apache.poi ooxml-schemas 1.4 com.itextpdf itext-asian 5.2.0 ``` - 项目使用介绍: - util类: - `src/main/java/com/example/word2pdf/core/WordUtils.java` - 调用样例类: - `src/main/java/com/example/word2pdf/Word2pdfApplication.java` - 使用说明: ```java Map map = new HashMap(); // this is template variable map.put("title", "九九互联"); map.put("contractNo", "WH-99-sh-0005"); map.put("name", "天津唐山科技有限公司"); map.put("name2", "天津科技有限公司"); map.put("date", new Date().toString()); map.put("rate1", "30%"); map.put("rate2", "34%"); map.put("rate3", "35%"); map.put("rate4", "50%"); map.put("rate5", "30%"); // this is the template path String srcPath = "applogs/pdf/test.docx"; // this is the output path .pdf格式 String destPath = "applogs/pdf/new-1.pdf"; // create file in 'applogs/pdf/' 下,可自行调整 WordUtils.searchAndReplace(srcPath, destPath, map); ``` - 实现原理: - poi 读取模版文件,并且把模版文件中的占位变量替换掉 - poi 生成新的word文件流 - poi covert word 2 pdf - export pdf file