`java 将本地excel文档转化成pdf
public static void excel2pdf(String inputPath,String Address) {
if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
return;
}
try {
// File pdfFile = new File("D:/wbcf1.pdf");// 输出路径
File pdfFile = new File(Address);
Workbook wb = new Workbook(inputPath);// 原始excel路径
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);
FileOutputStream fileOS = new FileOutputStream(pdfFile);
wb.save(fileOS, pdfSaveOptions);
// wb.save(fileOS, SaveFormat.PDF);
fileOS.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = OfficeToPdf.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;
}
调用 officeToPdf.excel2pdf(filePath, fileDir+outFilePdfPath);
效果显示