Search code examples
pythonpowerpointpython-pptx

Split ppt slides and save separately using python


I have .pptx file having 5 slides, I want to get each slide of ppt and save each slide in a separate ppt file using python. I have tried to do this using python-pptx but I was unable to get paste option for copied side by referring Python-pptx: copy slide link. I don't want use win32 method as I am working in Linux.


Solution

  • If you use Aspose.Slides for Python via .NET, you will easily split presentation slides and save them separately. The following code example shows you how to do this:

    import aspose.slides as slides
    
    with slides.Presentation('example.pptx') as presentation:
        for i in range(len(presentation.slides)):
            with slides.Presentation() as newPresentation:
                size = presentation.slide_size.size
                newPresentation.slide_size.set_size(size.width, size.height, slides.SlideSizeScaleType.DO_NOT_SCALE)
                newPresentation.slides.remove_at(0)
                newPresentation.slides.add_clone(presentation.slides[i])
                newPresentation.save(f'slide_{i + 1}.pptx', slides.export.SaveFormat.PPTX)
    

    You can also evaluate Aspose.Slides Cloud SDK for Python for presentation manipulating. This REST-based API allows you to make 150 free API calls per month for API learning and presentation processing. The following code example demonstrates how to do the same with Aspose.Slides Cloud:

    import asposeslidescloud
    
    from asposeslidescloud.configuration import Configuration
    from asposeslidescloud.apis.slides_api import SlidesApi
    
    configuration = Configuration()
    configuration.app_sid = 'myClientId'
    configuration.app_key = 'myClientKey'
    
    slidesApi = SlidesApi(configuration)
    response = slidesApi.split('example.pptx', None, 'pptx')
    

    Sometimes it is necessary to split a presentation without any code. Aspose Online Splitter can help you with this.

    I work at Aspose.