Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Mar 02, 2022 4:24 pm

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

GuiPATRY
 
Posts: 37
Joined: Wed Feb 17, 2021 10:18 am

Wed Mar 02, 2022 4:52 pm

Additionnal informations :
The error occurs for each page of the generated PDF, the getImagesInfo() method throwing an exception for each one

GuiPATRY
 
Posts: 37
Joined: Wed Feb 17, 2021 10:18 am

Thu Mar 03, 2022 2:53 am

Hello,

Thanks for your inquiry!

I tested the code and the file you provided with the latest Spire.Office for java version 5.2.2, but did not reproduce your issue. Here I attached my testing code, besides, since the "document" and "documentPDF" is unclear in your code, I just input a sample PDF as the final PDF.
Code: Select all
      Presentation presentation = new Presentation();
      presentation.loadFromFile("E:\\testdoc\\Problematic PPT\\Problematic PPT.pptx");
      ByteArrayOutputStream outstream = new ByteArrayOutputStream();
      presentation.saveToFile(outstream, com.spire.presentation.FileFormat.PDF);
      ByteArrayInputStream instream = new ByteArrayInputStream(outstream.toByteArray());
      PdfDocument source = new PdfDocument(instream);
      // add the docmuent to the final PDF
      // (since the "document" is unclear, I just input a sample page as the final PDF
      PdfDocument document = new PdfDocument();
      document.loadFromFile("E:\\testdoc\\sample.pdf");
      document.appendPage(source);
      PdfPageCollection pages = document.getPages();
      for (int i = 0; i < pages.getCount(); i++) {
         System.out.println("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());
               }
            }
         }
      }
   }


If you are not using the latest version, I just recommend that you can have a try first. If the issue still exists, please provide us with the full code you are using, and all of your input files for further investigate. Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Thu Mar 03, 2022 12:14 pm

Hello
I used your code, with version 5.2.2 of the library and the same exception is still occurring at the same place

Code: Select all
private void testPPT() {
      displayVersions(); // display the version of java & SpireOffice
      try {

         // load PPT
         Presentation presentation = new Presentation();
         presentation.loadFromFile("datas/PPTProblem.pptx");

         // convert to PDF
         ByteArrayOutputStream outstream = new ByteArrayOutputStream();
         presentation.saveToFile(outstream, com.spire.presentation.FileFormat.PDF);
         ByteArrayInputStream instream = new ByteArrayInputStream(outstream.toByteArray());
         PdfDocument source = new PdfDocument(instream);

         // add the converted PPT to the "final" PDF
         PdfDocument document = new PdfDocument();
         // first add another file to the PDF
         document.loadFromFile("datas/ZPRN_ 1.PDF");
         document.appendPage(source);

         // Optimise images
         PdfPageCollection pages = document.getPages();
         for (int i = 0; i < pages.getCount(); i++) {
            System.out.println("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());
                  }
               }
            }
         }

      } catch (Exception e) {
         System.out.println(e.getMessage());
      }
   }


We are using a SAP JVM :
Java - version 1.8.0_221 by SAP AG
spire.office for java - version 5.2.2

I test with JRE 1.8 and the result is nearly the same (message : "null"); the exception being launched at the same point.
Java - version 1.8.0_181 by Oracle Corporation

Regards

GuiPATRY
 
Posts: 37
Joined: Wed Feb 17, 2021 10:18 am

Fri Mar 04, 2022 3:46 am

Hello,

Thanks for sharing more information!

I tested again, it is strange that the same code I tested yesterday can work well, but today I did reproduce the issue you mentioned. Anyway, the issue has been logged in our issue tracking system with the ticket SPIREPDF-4974 for further investigation.

We will let you know if there is any update. Sorry for the inconvenience caused.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Mar 23, 2022 10:06 am

Hello,

Glad to inform that we just released Spire.Office for Java 5.3.2 which fixed the SPIREPDF-4974, welcome to test it.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Wed Mar 23, 2022 1:48 pm

Hello

New version is working fine, without any problem.

Thanks & Regards
Guillaume

GuiPATRY
 
Posts: 37
Joined: Wed Feb 17, 2021 10:18 am

Fri Mar 25, 2022 1:32 am

Hello,

Glad to hear that! If you encounter any issues related to our products in the future, just feel free to contact us.
Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF