没有office组件,要转换pdf,可以使用aspose的组件 aspose-cells
就是当文件有点大时对内存消耗比较大
1、配置
需要aspose-cells-8.5.2.jar 和 license.xml 相关下载
2、使用
可参照: 官方文档
1、license认证方法,就是加载license.xml文件进行认证
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = MainApp.class.getClassLoader().getResourceAsStream("license.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
2、excel转pdf
public static void excel2Pdf(String inFilePath, String outFilePath) {
if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
return;
}
try {
File pdfFile = new File(outFilePath);// 输出路径
if (pdfFile.exists()) {
pdfFile.delete();
}
Workbook wb = new Workbook(inFilePath);// 原始excel路径
FileOutputStream fileOS = new FileOutputStream(pdfFile);
PdfSaveOptions options = new PdfSaveOptions(SaveFormat.PDF);
options.setOnePagePerSheet(true);
wb.save(fileOS, options);
fileOS.close();
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.getMessage());
}
}