Failed to Get the Blank Layout Slide from a PowerPoint Presentation in Java

I am having an issue with this method - the second parameter is returning null…

IMasterLayoutSlideCollection layoutSlides = 
    pres.getMasters().get_Item(0).getLayoutSlides();

slide222 = pres.getSlides().insertEmptySlide(slide.getSlideNumber(), 
    layoutSlides.getByType(SlideLayoutType.Blank));

this line is returning null…

layoutSlides.getByType(SlideLayoutType.Blank)

Any idea why?

I have read that I can add the a slide type - but I cannot seem to figure out how to add the ‘Blank’ type.

@john.nelson,
Thank you for contacting support. I am working on the issue and will get back to you as soon as possible.

@john.nelson,
Thank you for your patience.

If I understand the issue correctly, the PowerPoint presentation you are using does not have the Blank layout slide. To cover such cases, you should first check if the layout slide exists. If not, you can add the layout slide and then use it to create regular slides.

IMasterLayoutSlideCollection layoutSlides = 
    pres.getMasters().get_Item(0).getLayoutSlides();

var blankLayout = layoutSlides.getByType(SlideLayoutType.Blank);
if(blankLayout == null) {
    blankLayout = layoutSlides.add(SlideLayoutType.Blank, "Blank");
}

var slide222 = pres.getSlides().insertEmptySlide(
    slide.getSlideNumber(), blankLayout);

This s the code I use and get this error…

ILayoutSlide layoutSlide = null;

layoutSlide = layoutSlides.getByType(SlideLayoutType.Blank);
if (layoutSlide == null) {

    layoutSlide = layoutSlides.add(SlideLayoutType.Blank, "Blank");
}

it crashes on this line…

layoutSlide = layoutSlides.add(SlideLayoutType.Blank, "Blank");

I get this error in tomcat logs…

java.lang.Thread.run(Unknown Source)
at com.aspose.slides.GlobalLayoutSlideCollection.add(Unknown Source)
at com.aspose.slides.MasterLayoutSlideCollection.add(Unknown Source)
.
.
.
Controller Exception throwing Throwable:null

@john.nelson,
Could you please share the presentation file you used?

RREComprehensiveRiskTags.zip (48.5 KB)

@john.nelson,
Unfortunately, I was unable to reproduce the error you encountered. Please note that the PowerPoint presentation already contains the Blank layout slide, and the line of code you mentioned is not actually executed. Please check it carefully.

These lines return null running that presentation…

ILayoutSlide layoutSlide = null;
layoutSlide = layoutSlides.getByType(SlideLayoutType.Blank);
if (layoutSlide == null)
      logIt("returning null");

@john.nelson,
Could you please share more details on how to reproduce the error you encountered?

check out my very first comment. I load the ppt file I sent you and then go through the code above. And this returns null…

ILayoutSlide layoutSlide = null;
layoutSlide = layoutSlides.getByType(SlideLayoutType.Blank);

@john.nelson,
Unfortunately, I was never able to reproduce the problem you described. Please check your results using the latest version of Aspose.Slides for Java. If the issue persists, please share the following information:

  • standalone complete code example
  • Aspose.Slides version you used
  • any additional information

I’m on version 19.2

@john.nelson,
Unfortunately, I was also unable to reproduce the problem with version 19.2. Please share a standalone complete code example.

I figured it out - no blank slide in the master slide.

The code was working all along.

Thank for all of your help.

@john.nelson,
We are glad to know that the issue has been resolved on your end. Thank you for using Aspose.Slides.