package cn.digitaltest.util;
import java.io.*;
import com.aspose.cells.*; //引入aspose-cells-8.5.2.jar包
public class Pdf {
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = Test.class.getClassLoader().getResourceAsStream("xlsxlicense.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
}
catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void excel2pdf(String Address) {
if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
return;
}
try {
File pdfFile = new File("C:/inetpub/wwwroot/web/file/pdf1.pdf");// 输出路径
Workbook wb = new Workbook(Address);// 原始excel路径 FileOutputStream fileOS = new FileOutputStream(pdfFile);
wb.save(fileOS, SaveFormat.PDF);
fileOS.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}