Splitting Presentation into Individual Slides Throws NullPointerException

My application needs to split presentations into individual slides. When doing this operation sequentially in a loop, it works fine with the following test case:

@Test
public void testSequentialSave() throws IOException {

    Presentation presentation = new Presentation("C:\\Users\\z.a\\Desktop\\Test5.pptx");
    presentation.getSlides().forEach(slide -> {
        System.out.println(slide.getSlideId());

        Presentation singleSlide = new Presentation();

        singleSlide.getSlides().addClone(slide);
        singleSlide.getSlides().removeAt(0);

        ByteArrayOutputStream singleSlideOutputStream = new ByteArrayOutputStream();
        singleSlide.save(singleSlideOutputStream, SaveFormat.Pptx);

        try (OutputStream outputStream = new FileOutputStream(
                "C:\\Users\\z.a\\Desktop\\Test1Result " + slide.getSlideId() + ".pptx")) {
            singleSlideOutputStream.writeTo(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
}

However, this operation is slow. It takes on average 3 seconds to get one slide out. I trying to use parallel stream to speed up the process in the following way:

    @Test
public void testParallelSave() throws IOException {

    Presentation presentation = new Presentation("C:\\Users\\z.a\\Desktop\\Test1.pptx");
    ISlide[] slidesArray = presentation.getSlides().toArray();
    Arrays.asList(slidesArray).stream().parallel().forEach(slide -> {
        System.out.println(
                "Thread : " + Thread.currentThread().getName() + ", value: " + ((ISlide) slide).getSlideId());

        Presentation singleSlide = new Presentation();
        singleSlide.getSlides().addClone((ISlide) slide);
        ByteArrayOutputStream singleSlideOutputStream = new ByteArrayOutputStream();
        singleSlide.save(singleSlideOutputStream, SaveFormat.Pptx);

        try (OutputStream outputStream = new FileOutputStream(
                "C:\\Users\\z.a\\Desktop\\Test1Result " + slide.getSlideId() + ".pptx")) {
            singleSlideOutputStream.writeTo(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
}

However this results in a error. Stack trace:

Caused by: java.lang.NullPointerException
at com.aspose.slides.ThreeDFormatPPTXSerialization.do(Unknown Source)
at com.aspose.slides.rq.do(Unknown Source)
at com.aspose.slides.bg.do(Unknown Source)
at com.aspose.slides.vs.do(Unknown Source)
at com.aspose.slides.ald.do(Unknown Source)
at com.aspose.slides.agp.do(Unknown Source)
at com.aspose.slides.agp.do(Unknown Source)
at com.aspose.slides.age.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.SlideCollection.addClone(Unknown Source)
at AsposeTests.lambda$1(AsposeTests.java:60)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Why is it not possible to perform this operation in parallel? Are there any other means to speed up the splitting of powerpoint file into individual slides?

@zasbrtn,
Welcome to our community! Could you please share the PPTX file that can be used to reproduce the issue? Also, please specify the version of Aspose.Slides you are using and check the issue with the latest version.

Hi, looks like this forum doesn’t accept PPTX file. However, I have reproduced the issue with different PPTX files.

Sorry, the file you are trying to upload is not authorized (authorized extensions: jpg, jpeg, png, gif, zip, pdf).

I’m using Aspose.Slides 21.3 which is the latest version.

@zasbrtn,
You can compress the PPTX file to a zip archive and upload it. Also, you can share a link to the PPTX file in Google Drive or Dropbox.

@zasbrtn,
I reproduced the issue but received another error. Your presentation sample could be useful to investigate the issue better.

I observed that the stack trace may be different depending on the input. Another variation of the error:

Caused by: java.lang.NullPointerException
at com.aspose.slides.acu.do(Unknown Source)
at com.aspose.slides.ap3.do(Unknown Source)
at com.aspose.slides.apm.do(Unknown Source)
at com.aspose.slides.apm.do(Unknown Source)
at com.aspose.slides.r.do(Unknown Source)
at com.aspose.slides.rq.do(Unknown Source)
at com.aspose.slides.rq.do(Unknown Source)
at com.aspose.slides.bg.do(Unknown Source)
at com.aspose.slides.vs.do(Unknown Source)
at com.aspose.slides.ald.do(Unknown Source)
at com.aspose.slides.agp.do(Unknown Source)
at com.aspose.slides.agp.do(Unknown Source)
at com.aspose.slides.age.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknown Source)
at com.aspose.slides.MasterSlideCollection.do(Unknoown Source)
at AsposeTests.lambda$1(AsposeTests.java:60)

testpptxs.zip (4.1 MB)

Attached a zip containing the PPTX I tested with.

@zasbrtn,
Thank you for the presentation samples. I have logged the issue in our tracking system with ID SLIDESJAVA-38499. Our development team will investigate it. You will be notified when the issue is fixed.

Unfortunately, I see no other way to do that.

Hi @Andrey_Potapov, do you have an ETA for this topic?

@zasbrtn,
I requested some ETA for this issue from our development team. I will let you know as soon as possible.

@zasbrtn,
Our development team investigated the issue. Unfortunately, such operations are not supported. Please look at the next article: Multithreading in Aspose.Slides. The same goes for Aspose.Slides for Java.