问题遇到的现象和发生背景
我在使用asponse将PPT转成PDF时,提示我空指针异常
问题相关代码,请勿粘贴截图
public static void main(String[] args) throws IOException {
String outPath = "D:/project/123.pdf";
String inPath = "D:/project/22.pptx";
if (!isPptLicense()) {
return;
}
FileOutputStream outputStream = null;
//读取ppt文件
FileInputStream fileInput = new FileInputStream(inPath);
System.out.println(fileInput.toString());
Presentation pres = new Presentation(fileInput);
//指定输出路径
outputStream = new FileOutputStream(new File(outPath));
//输出
pres.save(outputStream, com.aspose.slides.SaveFormat.Pdf);
outputStream.close();
}
private static boolean isPptLicense() {
boolean result = false;
try {
String license =
"<License>\n" +
" <Data>\n" +
" <Products>\n" +
" <Product>Aspose.Total for Java</Product>\n" +
" <Product>Aspose.Words for Java</Product>\n" +
" </Products>\n" +
" <EditionType>Enterprise</EditionType>\n" +
" <SubscriptionExpiry>20991231</SubscriptionExpiry>\n" +
" <LicenseExpiry>20991231</LicenseExpiry>\n" +
" <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>\n" +
" </Data>\n" +
" <Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>\n" +
"</License>";
InputStream is = new ByteArrayInputStream(license.getBytes("UTF-8"));
com.aspose.slides.License aposeLic = new com.aspose.slides.License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
运行结果及报错内容
我的解答思路和尝试过的方法
我最开始以为是我路径的问题,因此我尝试把路径改为D:\project\123.pdf,但是还是不行。同样的方法我去处理word和Excel转PDF都没问题,唯独PPT失败,我使用的slides版本是15.9.0