word转成PDF
/**
* word文档转成pdf(doc、docx、txt)
* @param oldFilePath 旧文件地址
* @param toFilePath 生成文件地址
* @param suffix 文件后缀
* @return
*/
public static boolean wordtoPDF(String oldFilePath, String toFilePath,String suffix){
try {
// 新建一个空白pdf文档
File file = new File(toFilePath);
com.spire.doc.Document doc = new com.spire.doc.Document();
//判断文档后缀名称
switch (suffix){
case "docx":
doc.loadFromFile(oldFilePath, FileFormat.Docx);
break;
case "doc":
doc.loadFromFile(oldFilePath, FileFormat.Doc);
break;
case "txt":
doc.loadFromFile(oldFilePath, FileFormat.Txt);
break;
}
doc.saveToFile(toFilePath, FileFormat.PDF);
doc.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}