Hello
When optimizing the images (image compression) from a PPT that was converted into PDF, I get the following error :
java.lang.NullPointerException: while trying to invoke the method com.spire.office.packages.sprvow.spr℠§—(com.spire.office.packages.sprlama, com.spire.office.packages.sprdqw, com.spire.office.packages.sprnmy, bool) of a null object loaded from local variable 'a'
The PPTX is converted to PDF with the following code :
// load document
Presentation presentation = new Presentation();
if (inputFile.stream == null) {
presentation.loadFromFile(inputFile.filename);
} else {
presentation.loadFromStream(inputFile.stream, com.spire.presentation.FileFormat.AUTO);
}
// put it into PDF destination doc
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
presentation.saveToFile(outstream, com.spire.presentation.FileFormat.PDF);
ByteArrayInputStream instream = new ByteArrayInputStream(outstream.toByteArray());
source = new PdfDocument(instream);
// add the docmuent to the final PDF
documentPDF.appendPage(source);
Image compression is done using the following code :
PdfPageCollection pages = document.getPages();
for (int i = 0; i < pages.getCount(); i++) {
responses.add("I:Page " + i);
PdfPageBase page = pages.get(i);
if (page != null) {
PdfImageInfo[] infos = page.getImagesInfo();
if (infos != null) {
for (PdfImageInfo pdfImageInfo : infos) {
page.tryCompressImage(pdfImageInfo.getIndex());
}
}
}
}
The full stack is following
Exception in thread "main" java.lang.NullPointerException: while trying to invoke the method com.spire.office.packages.sprvow.spr℠§—(com.spire.office.packages.sprlama, com.spire.office.packages.sprdqw, com.spire.office.packages.sprnmy, bool) of a null object loaded from local variable 'a'
at com.spire.office.packages.sprnmy.spr℉↡—(Unknown Source)
at com.spire.office.packages.sprvow.spr℠§—(Unknown Source)
at com.spire.office.packages.sprnmy.spr℉↡—(Unknown Source)
at com.spire.office.packages.sprhty.spr℉↡—(Unknown Source)
at com.spire.pdf.PdfPageBase.spr▁┘—(Unknown Source)
at com.spire.pdf.PdfPageBase.getImagesInfo(Unknown Source)
at FileConcatenationV3.optimiseImages(FileConcatenationV3.java:265)
at FileConcatenationV3.concatenateV4(FileConcatenationV3.java:153)
at FileConcatenationV3.main(FileConcatenationV3.java:89)
the PPTX is joigned to this message
Regards