上一篇文章介绍了使用spire.doc合并多个doc文件成一个文件的方法,下面将介绍将doc文件转成pdf的方法,这里我使用的是org.jodconverter中的方法,相关依赖见上一篇.
使用方式如下:
@Autowired
private DocumentConverter converter;
@Value("${yourFilePath}")
private String reviewPath;
/**
*
* @param fileName 文件名
* @param realPath 要转换的doc的文件地址
* @return
*/
public String mergeConversion(String fileName, String docPath) {
File file = new File(docPath);
//转换成pdf并保存结果文件
if (!fileName.endwith(".pdf")) {
fileName = fileName.split("\\.")[0].concat(".pdf");
converter.convert(file).to(new File(reviewPath + fileName)).execute();
File file2 = new File(reviewPath + fileName);
while (true) {
if (file2.exists()) {
log.info("转换成pdf文件成功...");
break;
}
}
}