`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);
效果显示

本文介绍了一种使用Java将Excel文件转换为PDF的方法。通过指定输入路径和输出路径,可以实现转换过程,并提供了去除水印的License验证。该方法利用了`Workbook`类和`PdfSaveOptions`来设置转换选项。
5512

被折叠的 条评论
为什么被折叠?



