Set number of pages to convert

Hi,

I am using Aspose.Slides.dll (5.2.0) and I can correctly convert presentations into PDF documents. I would like to set the number of pages to convert (e.g. obtain a PDF with max 100 pages).
I have read the API reference for the Save method, but I cannot find any useful overload (it always saves all slides of a presentation ).
Is there a workaround I can use, or do you plan to include overloads in the next version of Aspose.Slides.dll ?

Thanks.

Max

Hi Max,

Thanks for your interest in Aspose.Slides.

You can export a presentation file to PDF with a specific number of pages. Please use the following code snippet to export first 100 pages of PPT into PDF file.

//Instantiate a Presentation object that represents a PPT file
Presentation presSource = new Presentation(@“d:\presentation.ppt”);
Presentation presTarget = new Presentation();
int MaxPages = 100;

for (int i = 0; i < MaxPages; i++)
{
// get slide
Slide slide = presSource.Slides[i];
//Cloning the selected slide at the end of the same presentation file
presTarget.CloneSlide(slide, presTarget.Slides.LastSlidePosition + 1);
}

//removing first slide
presTarget.Slides.RemoveAt(0);
//
presTarget.Save(@“d:\AsposeOutput.pdf”, Aspose.Slides.Export.SaveFormat.Pdf);


Hi Tahir,

Thank you for your reply. I have tested your code but the target presentation (presTarget) does not keep the style of the original presentation (e.g. font color, background color, etc.). So I decided to remove slides from the original presentation until I reach the specified number of pages:

>>>
Presentation pres = new Presentation(sourceFileName);
totalPages = pres.Slides.Count;

for (int i = totalPages - 1; i >= maxPages; i–)
{
pres.Slides.RemoveAt(i);
}
<<<

This seems to work correctly, but I have found an issue with the attached ppt file. If you open the presentation with PowerPoint you will see 15 slides. Instead if you debug the code, you will see that pres.Slides.Count is 16 (and the loop fails to remove the right number of slides…).

Please help.
Thanks.

Max

Hi Max,

Please use the LastSlidePosition property of slides class instead of count. The count property of slides class returns the number of elements in the collection (Normal Slides, Slide Masters and Title Masters) and LastSlidePosition returns the position of the last slide in a presentation.

Hi Tahir,

I have tested your code and it seems to work correctly.
I am also using the PresentationEx class:

>>>

PresentationEx pres = new PresentationEx(sourceFileName);
totalPages = pres.Slides.Count;
<<<

I cannot find the LastSlidePosition property for this class … is it correct to use the Count property in this case, or should I use another property?

Thank you for your answer.

Max

Hi Max,

For PPTX you need to do following to get total number of slides.

totalPages = pres.Slides.Count - pres.Masters.cout;

Hi Tahir,

I have tested your code with the file in attachment (it is a .pptx presentation) and I get the following results:

- pres.Slides.Count = 27
- pres.Slides.Count - pres.Masters.count = 26

If you open the .pptx file with PowerPoint, you will see that it contains 27 slides…

Thanks.

Max

Hi Max,

Please accept my apology for misunderstanding. For PPTX the Slides.count property returns to total number of normal slides.