word转PDF
words.jar 实现word文件转为PDF,支持doc和docx
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import com.seeyon.ctp.util.FileUtil;
import java.io.*;
public class Word2PdfUtil {
/**
* 将word文档, 转换成pdf, 中间替换掉变量
* @param wordFilePath 源为word文档
* @param pdfFilePath 目标输出
* @throws Exception
*/
public static boolean wordConverterToPdf(String wordFilePath, String pdfFilePath) {
Document doc = null;
FileOutputStream pdfFile = null;
try {
doc = new Document(wordFilePath);
File filePdf = new File(pdfFilePath);
pdfFile = new FileOutputStream(filePdf);
doc.save(pdfFile, SaveFormat.PDF);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
try {
pdfFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}