Python: Change Slide Size in PowerPoint

2024-03-04 01:39:48 Written by  support iceblue
Rate this item
(0 votes)

In PowerPoint, properly sized slides help make the document look professional. When giving presentations in different scenarios, adjusting slide sizes to match the aspect ratio of the projector or screen ensures an optimal viewing experience for all audience members, thus increasing engagement. In this article, you will learn how to change the slide size of a PowerPoint presentation in Python using Spire.Presentation for Python.

Install Spire.Presentation for Python

This scenario requires Spire.Presentation for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.

pip install Spire.Presentation

If you are unsure how to install, please refer to this tutorial: How to Install Spire.Presentation for Python on Windows

Change the Slide Size to a Preset Size in Python

Spire.Presentation for Python provides the Presentation.SlideSize.Type property to set or change the slide size to a preset size. The following are the detailed steps.

  • Create a Presentation instance.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Change the slide size of the presentation using Presentation.SlideSize.Type property.
  • Save the result document using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *

# Create a Presentation instance
presentation = Presentation()

# Load a PowerPoint document 
presentation.LoadFromFile("sample.pptx")

# Set or change the slide size 
presentation.SlideSize.Type = SlideSizeType.Screen4x3

# Save the result document
presentation.SaveToFile("ChangeSlideSize.pptx", FileFormat.Pptx2016)
presentation.Dispose()

Python: Change Slide Size in PowerPoint

Change the Slide Size to a Custom Size in Python

Customizing the size of slides requires changing the slide size type to Custom first, and then you can set a desired size through the Presentation.SlideSize.Size property. The following are the detailed steps.

  • Create a Presentation instance.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Change the slide size type to custom using Presentation.SlideSize.Type property.
  • Customize the slide size using Presentation.SlideSize.Size property.
  • Save the result document using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *

# Create a Presentation instance
presentation = Presentation()

# Load a PowerPoint document 
presentation.LoadFromFile("sample.pptx")

# Change the slide size type to custom
presentation.SlideSize.Type = SlideSizeType.Custom

# Set the slide size
presentation.SlideSize.Size = SizeF(900.0,600.0)

# Save the result document
presentation.SaveToFile("CustomSlideSize.pptx", FileFormat.Pptx2016)
presentation.Dispose()

Python: Change Slide Size in PowerPoint

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Additional Info

  • tutorial_title:
Last modified on Thursday, 25 April 2024 02:19