We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Adding Slides into a Section

Hi,

I am trying to create Section and add Slides into it through com.aspose.slides.Presentation.

new Presentation(“file_name”).getSections().addSection(“Section_Name”,iSlideObj);.

It throws com.aspose.slides.exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

I tried with both new Presentation object and also on existing Presentation file, it throws exception in both the cases.

Similar excpetion is thrown when I add empty section.

Can you please help me to achieve this or any alternative approach?

Thanks in advance,
Raghuraman K

PS: We are using licensed Aspose Slides 17.8-jdk16 version.

@raghuramank,

I have observed your comments. Can you please share source presentation along with environment details with so that we may further investigate to help you put. Before sharing requested information i suggest you to please try to use Aspose.Slides latest version 17.9 on your end and if there is still an issue than please share requested information with us.

@raghuramank,

I have tried using following sample code on my end and there seems to be issue in adding section.

 public static void TestSlideSections()
{
    Presentation pres = new Presentation();
    
    pres.getSections().addSection("SECTION1",pres.getSlides().get_Item(0));
    pres.save("C:\\Aspose Data\\TestSection.pptx",SaveFormat.Pptx);
}

Can you please try using the same on your end and provide the source presentation as well that you are using on your end.

Hi,

I did try similar sample code to add section on existing slides in input presentation file.

public class TestAddSection {

public static void main(String[] args) {
	
	// code to Include Licence file

	Presentation inputPres = new Presentation("C:\\MSDE\\Test\\Presentation\\input\\input_test.pptx");
	
	Presentation outputPres = new Presentation();
	
	ISlide iSlide1 = inputPres.getSlides().get_Item(0);
	outputPres.getSlides().addClone(iSlide1);
	
	//Slide 2 to be added to SECTION 1
	ISlide iSlide2 = inputPres.getSlides().get_Item(1);
	outputPres.getSections().addSection("SECTION1",iSlide2);
	
      /*	
            //iSlide 3 to be added to SECTION 2
	ISlide iSlide3 = inputPres.getSlides().get_Item(1);
	outputPres.getSections().addEmptySection("SECTION2", 1);
          */
	
	outputPres.save("C:\\MSDE\\Test\\Presentation\\output\\output_test.pptx", SaveFormat.Pptx);		
}

}

Below exception was thrown:

Exception in thread “main” class com.aspose.slides.exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: Parameter name: index
com.aspose.slides.Collections.Generic.List.get_Item(Unknown Source)
com.aspose.slides.SlideCollection.get_Item(Unknown Source)
com.aspose.slides.Section.getSlidesListOfSection(Unknown Source)
com.aspose.slides.atd.do(Unknown Source)
com.aspose.slides.aqe.if(Unknown Source)
com.aspose.slides.apv.do(Unknown Source)
com.aspose.slides.Presentation.do(Unknown Source)
com.aspose.slides.Presentation.do(Unknown Source)
com.aspose.slides.Presentation.if(Unknown Source)
com.aspose.slides.pl.(Unknown Source)
com.aspose.slides.pl.do(Unknown Source)
com.aspose.slides.apn.if(Unknown Source)
com.aspose.slides.Presentation.do(Unknown Source)
com.aspose.slides.Presentation.save(Unknown Source)

Since I am accessing through enterprise network, I cannot upload or send Input Presentation file. But it was a simple presentation file created with three plain slides with only text content in it.

@raghuramank,

Please share the source presentation reproducing the issue on your end so that we may be able to investigate the issue further on our end.

Hi Mudassir,

Please find the ppt file in .zip format.
input_test.zip (30.9 KB)

Thanks,
Raghuraman K

@raghuramank,

I have worked with the sample code and source presentation shared by you. Actually, the issue lies in your code. You are trying to add a slide from source presentation to a new section of target presentation, which is wrong. You first need to clone the slide from source presentation and then you can add that slide to particular section. The sections are logical divisions of slides inside slide collection only. Please try following alternate on your end.

ISlide iSlide2 = inputPres.getSlides().get_Item(1);
ISlide iSlideClone2 =outputPres.getSlides().addClone(iSlide2);
outputPres.getSections().addSection("SECTION1",iSlideClone2);

output_test.zip (35.9 KB)

Hi Mudassir,

Thanks a lot for your response and reaching out to solution.

I tested with sample code provided in previous post, there are no exceptions but the output file generated is corrupt.
File as generated is being prompted for repair when opened. I have tried this multiple times with same input file and consistently the output file is corrupt.
I have attached the generated out put file for reference.output_test.zip (41.4 KB)

screenshot_output_test_repair.PNG (47.9 KB)

Can you please help me in resolving this issue?

Also, we have upgraded to 17.9.1 version as per your suggestion in one of the posts.

Thanks,
Raghuraman K

@raghuramank,

I suuggest you to please try using Aspose.Slides for Java 17.9 on your end with following code. The output that I have obtained has no issue. For your kind reference, I have attached the generated presentation as well.

 public static void TestSections()
{
    String path="C:\\Aspose Data\\input_test\\";
    Presentation inputPres = new Presentation(path+"input_test.pptx");

    Presentation outputPres = new Presentation();

    ISlide iSlide1 = inputPres.getSlides().get_Item(0);
    outputPres.getSlides().addClone(iSlide1);

    //Slide 2 to be added to SECTION 1
    ISlide iSlide2 = inputPres.getSlides().get_Item(1);
    ISlide iSlideClone2 =outputPres.getSlides().addClone(iSlide2);
    outputPres.getSections().addSection("SECTION1",iSlideClone2);

    outputPres.save(path+"output_test2.pptx", SaveFormat.Pptx);		
}

output_test.zip (72.5 KB)

Hi Mudassir,

Thanks a lot for your support and quick turn around.
I was able to generate the file without any issue.
Instead of com.aspose.slides.SaveFormat by chance com.aspose.pdf.SaveFormat was imported into my sample code. I overlooked import statements. Since SaveFormat.pptx was from pdf API, output file was corrupted. Sorry to have troubled you on that :slight_smile:

Have a good one!

Regards,
Raghuraman K

@raghuramank,

It good to know things are working on your end. Please share with us if you encounter any issue while using API.