1- using Syncfusion . Presentation ;
1+ // Create a ZIP archive and set the compression level to Best.
2+ using Syncfusion . Presentation ;
3+ using Syncfusion . Compression . Zip ;
24
3- //Opens the source PPTX document.
5+ ZipArchive zipArchive = new ZipArchive ( ) ;
6+ zipArchive . DefaultCompressionLevel = Syncfusion . Compression . CompressionLevel . Best ;
7+
8+ // Open the source PowerPoint presentation.
49IPresentation sourcePptx = Presentation . Open ( Path . GetFullPath ( @"Data/Template.pptx" ) ) ;
510
6- //Iterates through each section.
11+ // Iterate through each section in the presentation.
712foreach ( ISection section in sourcePptx . Sections )
813{
9- //Creates a destination PPTX document. Existing presentations can also be used here.
14+ // Create a new destination presentation for the current section.
1015 IPresentation destinationPptx = Presentation . Create ( ) ;
11- // Clone the slides from the section and move to new PPTX document.
16+
17+ // Clone all slides from the current section and add them to the new presentation.
1218 foreach ( ISlide slide in section . Slides )
1319 {
1420 destinationPptx . Slides . Add ( slide . Clone ( ) , PasteOptions . SourceFormatting , sourcePptx ) ;
1521 }
16- //Saves the destination PPTX document.
17- string outputPath = Path . Combine ( Path . GetFullPath ( "Output" ) , section . Name + "_Slides.pptx" ) ;
18- destinationPptx . Save ( outputPath ) ;
22+ // Save the section presentation to a memory stream.
23+ MemoryStream memoryStream = new MemoryStream ( ) ;
24+ destinationPptx . Save ( memoryStream ) ;
25+
26+ // Add the generated presentation to the ZIP archive with the section name as the file name.
27+ string outputPath = Path . Combine ( section . Name + "_Slides.pptx" ) ;
28+ zipArchive . AddItem ( outputPath , memoryStream , true , Syncfusion . Compression . FileAttributes . Normal ) ;
29+
30+ // Close the destination presentation.
1931 destinationPptx . Close ( ) ;
2032}
21- //Closes the PPTX document.
33+
34+ // Save the ZIP archive containing all section presentations.
35+ zipArchive . Save ( Path . GetFullPath ( @"Output/Split-PowerPoint-by-sections.zip" ) ) ;
36+ // Close the ZIP archive.
37+ zipArchive . Close ( ) ;
38+ // Close the source presentation.
2239sourcePptx . Close ( ) ;
0 commit comments