摘要:word转pdf、easypoi、docx4j、springboot
使用相关依赖:
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-export-fo</artifactId>
<version>6.1.0</version>
</dependency>
本次功能数据需要前端传递数据到后端直接模板打印预览
springboot接口:
@ApiOperation(value = "打印预览接口",notes = "打印预览接口")
public void previewByTemp(@PathVariable("tempId")String tempId, @RequestBody String body, HttpServletResponse response){
pubCoverConfigService.previewByTemp(tempId,body,response);
}
实际处理方法:
//使用模板渲染参数
XWPFDocument document = WordExportUtil.exportWord07(tempFile.getAbsolutePath(), map);
//读取刚才渲染好的docx文件
FileInputStream tempIns=new FileInputStream(tempFile);
WordprocessingMLPackage mlPackage = WordprocessingMLPackage.load(tempIns);
//载入字体
mlPackage.setFontMapper(mapper);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(mlPackage);
//开始转换
Docx4J.toFO(foSettings, fos, Docx4J.FLAG_EXPORT_PREFER_XSL);
目前实现功能:列表及变量渲染
问题:
docx4j渲染在linux服务器上,会产生中文渲染失败,需要在服务器中支持中文字体