Document Operation

Document Operation (12)

A well-chosen background can enhance a presentation's appeal, but overly elaborate colors or images may distract viewers and obscure the main message. Additionally, when reusing templates, the original background may not suit the new content. In these cases, removing the background becomes essential to keep your slides clear and focused. This article will show you how to remove backgrounds from PowerPoint slides or slide masters in Python with Spire.Presentation for Python, giving you the flexibility to create clean, professional presentations that keep the audience's attention on what matters.

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

Remove Backgrounds from the Specified Slide

There are typically two types of backgrounds in PowerPoint: background colors and background images. Although these backgrounds differ in their setup, the method to clear them is the same - using the BackgroundType property provided by Spire.Presentation for Python. Let's take a closer look at how to remove backgrounds from a PowerPoint slide with it.

Steps to remove background from a specified slide:

  • Create an object for the Presentation class.
  • Load a PowerPoint presentation from the local storage using Presentation.LoadFromFile() method.
  • Get a certain slide with Presentation.Slides[] method.
  • Remove the background by configuring BackgroundType property to none.
  • Save the modified PowerPoint presentation using Presentation.SaveToFile() method, and release the memory.

Here is the code example of removing the background on the fourth slide:

  • Python
from spire.presentation import *

# Create a Presentation document object
presentation = Presentation()
# Read the presentation document from file
presentation.LoadFromFile("imagebackground.pptx")

# Get the fourth slide
slide = presentation.Slides[3]

# Remove the background by setting the background type
slide.SlideBackground.Type = BackgroundType.none

# Save the modified presentation
presentation.SaveToFile("RemoveBackground.pptx", FileFormat.Pptx2010)

# Release resource
presentation.Dispose()

Python: Remove Backgrounds from PowerPoint Slide or Slide Masters

Remove Backgrounds from All Slides

Batch-deleting all slide backgrounds follows nearly the same steps as deleting a single slide background. The main difference is that you'll need to loop through each slide before setting the background type to ensure no slides are missed.

Steps to remove backgrounds from PowerPoint slides in a batch:

  • Instantiate a Presentation class.
  • Specify the file path to read a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Loop through each slide in the presentation.
  • Remove all backgournds by applying BackgroundType.none property to each slide.
  • Save the updated PowerPoint presentation as a new file with Presentation.SaveToFile() method, and release the resource.

Below is the code example for removing each background from PowerPoint slides:

  • Python
from spire.presentation import *

# Create a Presentation document object
presentation = Presentation()
# Read the presentation document from file
presentation.LoadFromFile("presentation.pptx")

# Loop through each slide
for slide in presentation.Slides:
    # Remove the background image or color by setting the background type
    slide.SlideBackground.Type = BackgroundType.none

# Save the modified presentation
presentation.SaveToFile("RemoveBackground_allSlides.pptx", FileFormat.Pptx2010)

# Release resource
presentation.Dispose()

Python: Remove Backgrounds from PowerPoint Slide or Slide Masters

How to Remove Backgrounds from PowerPoint Slide Masters

If the slide background still exists after using the above method, you may need to remove the slide master's background instead. Unlike individual slides, setting the background of a slide master applies changes across all slides, so removing the slide master background can efficiently clear all backgrounds at once.

Steps to remove backgrounds from PowerPoint slide masters:

  • Create an instance of the Presentation class.
  • Load a presentation from the disk with Presentation.LoadFromFile() method.
  • Retrieve a specified slide master using Presentation.Masters[] method.
  • Access the background of the slide master with Masters.SlideBackground property.
  • Remove the background by setting BackgroundType property to none.
  • Save the newly modified PowerPoint presentation with Presentation.SaveToFile() method.

Note: Since the process of batch-removing slide master backgrounds is almost similar to deleting background from a slide master, this section will show the steps in the code comments rather than listing them separately.

Here is an example of removing the background from the third slide master:

  • Python
from spire.presentation import *


# Create a Presentation object
presentation = Presentation()

# Load the sample file from the disk
presentation.LoadFromFile("presentation.pptx")

# Get the third slide master
master = presentation.Masters[2]

# Access the background of the slide master
SlideBackground = master.SlideBackground

# Clear the background by setting the slide master background style to none
master.SlideBackground.Type = BackgroundType.none

# Loop through each slide master
#for master in presentation.Masters:
    # Set the background type to none to remove it
    #master.SlideBackground.Type = BackgroundType.none

# Save the result presentation
presentation.SaveToFile("remove_background.pptx", FileFormat.Pptx2013)

# Release resources
presentation.Dispose()

Python: Remove Backgrounds from PowerPoint Slide or Slide Masters

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.

When preparing multiple PowerPoint presentations with similar themes, copying slides helps to maintain consistency in terms of design, layout and content. This ensures that all presentations have a uniform appearance, which can enhance the aesthetics of your document. In this article, you will learn how to copy or clone slides in PowerPoint presentations 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

Copy Slides Within the Same Presentation with Python

You can clone a slide either at a specified location or at the end of a PowerPoint presentation through the Presentation.Slides.Insert(Index: int, slide: ISlide) or Presentation.Slides.AppendBySlide(slide: ISlide) methods. The following are the detailed steps.

  • Create a Presentation instance.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specified slide using Prenstion.Slides[] property.
  • Clone the slide to the end of the same presentation using Presentation.Slides.AppendBySlide() method.
  • Clone the slide to a specific position within the same presentation using Presentation.Slides.Insert() method.
  • Save the result file using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

inputFile ="Input1.pptx"
outputFile ="CloneSlidesWithinTheSame.pptx"

# Create a Presentation instance
ppt = Presentation()

#Load a PowerPoint presentation
ppt.LoadFromFile(inputFile)

# Get the first slide in the presentation
slide = ppt.Slides[0]

# Clone the slide to the end of the presentation
ppt.Slides.AppendBySlide(slide)

# Clone the slide to the third position within the presentation
ppt.Slides.Insert(2, slide)

# Save the result file 
ppt.SaveToFile(outputFile, FileFormat.Pptx2016)
ppt.Dispose()

Python: Copy Slides in PowerPoint Presentations

Copy Slides to Another Presentation with Python

Spire.Presentation for Python also allows you to load two PowerPoint files and then clone the slides from one presentation to another presentation. The following are the detailed steps.

  • Create a Presentation instance.
  • Load two PowerPoint presentations using Presentation.LoadFromFile() method.
  • Get two slides in the first presentation using Prenstion.Slides[] property.
  • Clone the first slide to a specific position in the second presentation using Presentation.Slides.Insert() method.
  • Clone the second slide to the end of the second presentation using Presentation.Slides.AppendBySlide() method.
  • Save the result file using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

inputFile_1 = "Input1.pptx"
inputFile_2 = "Input2.pptx"
outputFile ="CloneSlidesToAnother.pptx"

# Load the first PowerPoint presentation
sourcePPT = Presentation()
sourcePPT.LoadFromFile(inputFile_1)

# Load the second PowerPoint presentation
destPPT = Presentation()
destPPT.LoadFromFile(inputFile_2)

# Get two slides in the first presentation
slide1 =sourcePPT.Slides[1]
slide2 =sourcePPT.Slides[2]

# Clone slide1 to the second position in the second presentation
destPPT.Slides.Insert(1, slide1)

# Clone slide2 to the end of the second presentation
destPPT.Slides.AppendBySlide(slide2)

# Save the second presentation
destPPT.SaveToFile(outputFile, FileFormat.Pptx2016)
destPPT.Dispose()

Python: Copy Slides in PowerPoint Presentations

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.

Rearranging slides in a PowerPoint presentation is a simple but essential skill. Whether you need to change the order of your points, group related slides together, or move a slide to a different location, the ability to efficiently reorganize your slides can help you create a more coherent and impactful presentation.

In this article, you will learn how to rearrange slides in a PowerPoint document 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 system 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

Rearrange Slides in a PowerPoint Document in Python

To reorder the slides in PowerPoint, two Presentation objects were created - one for loading the original document, and one for creating a new document. By copying the slides from the original document to the new one in the desired sequence, the slide order could be easily rearranged.

The following are the steps to rearrange slides in a PowerPoint document using Python.

  • Create a Presentation object.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Specify the slide order within a list.
  • Create another Presentation object for creating a new presentation.
  • Add the slides from the original document to the new presentation in the specified order using Presentation.Slides.AppendBySlide() method.
  • Save the new presentation to a PPTX file using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
presentation = Presentation()

# Load a PowerPoint file
presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.pptx")

# Specify the new slide order within a list
newSlideOrder = [4,2,1,3]

# Create another Presentation object
new_presentation =  Presentation()

# Remove the default slide
new_presentation.Slides.RemoveAt(0)

# Iterate through the list
for i in range(len(newSlideOrder)):

    # Add the slides from the original PowerPoint file to the new PowerPoint document in the new order
    new_presentation.Slides.AppendBySlide(presentation.Slides[newSlideOrder[i] - 1])

# Save the new presentation to file
new_presentation.SaveToFile("output/NewOrder.pptx", FileFormat.Pptx2019)

# Dispose resources
presentation.Dispose()
new_presentation.Dispose()

Python: Rearrange Slides in a PowerPoint Document

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.

Slide Master in PowerPoint presentations is a powerful feature that lies at the heart of designing consistent and professional-looking slideshows. It's essentially a blueprint or a template that controls the overall design and layout of the slides, allowing users to establish uniformity across presentations without having to manually format each slide individually. In this article, we will explore how to harness the power of Spire.Presentation for Python to create, modify, and apply slide masters in PowerPoint presentations within Python programs.

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: How to Install Spire.Presentation for Python on Windows

Create and Apply Slide Masters in PowerPoint Presentations

Every PowerPoint presentation in PowerPoint, regardless of whether it is newly created or not, will have at least one slide master. Developers can modify the default master or create new ones and apply them to slides with Spire.Presentation for Python to achieve a consistent style and content layout across the presentation.

The detailed steps for creating new slide masters and applying them to the slides in a presentation file are as follows:

  • Create an object of Presentation class and load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Create slide masters using Presentation.Masters.AppendSlide() method.
  • Use the methods under IMasterSlide class to set the backgrounds, customize color schemes, insert images, shapes, and text, etc.
  • Apply the slide masters to specific slides through ISlide.Layout property.
  • Save the presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create an instance of Presentation class
pres = Presentation()

# Load a Presentation file
pres.LoadFromFile("Sample.pptx")

# Add a cover slide master and a body slide master
master1 = pres.Masters.AppendSlide(pres.Masters.get_Item(0))
coverMaster = pres.Masters.get_Item(master1)
master2 = pres.Masters.AppendSlide(pres.Masters.get_Item(0))
bodyMaster = pres.Masters.get_Item(master2)

# Set background images for the two slide masters
pic1 = "Background1.jpg"
pic2 = "Background2.jpg"

rect = RectangleF.FromLTRB (0, 0, pres.SlideSize.Size.Width, pres.SlideSize.Size.Height)
coverMaster.SlideBackground.Fill.FillType = FillFormatType.Picture
image1 = coverMaster.Shapes.AppendEmbedImageByPath (ShapeType.Rectangle, pic1, rect)
coverMaster.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image1.PictureFill.Picture.EmbedImage

bodyMaster.SlideBackground.Fill.FillType = FillFormatType.Picture
image2 = bodyMaster.Shapes.AppendEmbedImageByPath (ShapeType.Rectangle, pic2, rect)
bodyMaster.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image2.PictureFill.Picture.EmbedImage

# Insert a logo to the body slide master
logo = "Logo.png"
bodyMaster.Shapes.AppendEmbedImageByPath(ShapeType.Rectangle, logo, RectangleF.FromLTRB(pres.SlideSize.Size.Width - 110, 10, pres.SlideSize.Size.Width - 10, 110))

# Insert text to the body slide master
shape = bodyMaster.Shapes.AppendShape(ShapeType.Rectangle, RectangleF.FromLTRB(pres.SlideSize.Size.Width - 210, 110, pres.SlideSize.Size.Width - 10, 150))
shape.Fill.FillType = FillFormatType.none
shape.Line.FillType = FillFormatType.none
shape.TextFrame.Text = "Spire.Presentation"

# Set the color scheme for the two slide masters
coverMaster.Theme.ColorScheme.Accent1.Color = Color.get_Red()
coverMaster.Theme.ColorScheme.Accent2.Color = Color.get_Blue()

bodyMaster.Theme.ColorScheme.Accent1.Color = Color.get_Brown()
coverMaster.Theme.ColorScheme.Accent2.Color = Color.get_Green()

# Apply the first master with layout to the first slide
pres.Slides.get_Item(0).Layout = coverMaster.Layouts.GetByType(SlideLayoutType.Title)

# Apply the second master with layout to other slides
for i in range(1, pres.Slides.Count):
    pres.Slides.get_Item(i).Layout = bodyMaster.Layouts.GetByType(SlideLayoutType.TitleAndObject)

# Save the document
pres.SaveToFile("output/CreateAndApplySlideMaster.pptx", FileFormat.Pptx2016)
pres.Dispose()

Python: Create, Modify, and Copy Slide Master in PowerPoint Presentations

Modify Slide Masters in PowerPoint Presentations

A presentation can have multiple slide masters, which can be applied to different slides to achieve a unified style application and modification for different types of slides.

The Presentation.Masters.get_Item() method in Spire.Presentation for Python allows developers to retrieve the specified slide master in the presentation by index and modify the master. The following step-by-step example demonstrates how to retrieve a slide master and modify its background, color scheme, and embedded images:

  • Create an object of Presentation class and load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a slide master through Presentation.Masters property.
  • Use the methods under IMasterSlide class to change the background, set the color scheme, delete and insert text and images, etc.
  • Save the presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create an object of Presentation
pres = Presentation()

# Load a PowerPoint presentation
pres.LoadFromFile("output/CreateAndApplySlideMaster.pptx")

# Get the third slide master
master = pres.Masters[2]

# Change the background
master.SlideBackground.Type = BackgroundType.Custom
master.SlideBackground.Fill.FillType = FillFormatType.Solid
master.SlideBackground.Fill.SolidColor.Color = Color.get_LightBlue()

# Change the color sheme
master.Theme.ColorScheme.Accent1.Color = Color.get_Red()
master.Theme.ColorScheme.Accent2.Color = Color.get_Green()

# Remove the pictures in the slide master
pictures = [shape for shape in master.Shapes if isinstance(shape, SlidePicture)]
for picture in pictures:
    master.Shapes.Remove(picture)

# Change the text in the slide master
texts = [shape for shape in master.Shapes if isinstance(shape, IAutoShape)]
for text in texts:
    if len(text.TextFrame.Text) != 0:
        text.TextFrame.Text = "Spire.Presentation for Python"

# Save the presentation
pres.SaveToFile("output/ModifySlideMaster.pptx", FileFormat.Pptx2016)
pres.Dispose()

Python: Create, Modify, and Copy Slide Master in PowerPoint Presentations

Copy Slide Masters Between PowerPoint Presentations

Applying the slide style of a presentation to another presentation can be achieved by copying the slide master between presentations and applying the master style to the specified slides. The following are the steps to copy the slide master between presentations and apply it to the specified slides:

  • Create two objects of Presentation class and load two presentation documents using Presentation.LoadFromFile() method.
  • Get the slide master of the second presentation using Presentation.Masters.get_Item() method.
  • Add the slide master to the first presentation using Presentation.Masters.AppendSlide() method.
  • Apply the slide master to the slides in the second presentation through ISlide.Layout property.
  • Save the first presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *
from spire.presentation.common import *

# Create two objects of Presentation
pres1 = Presentation()
pres2 = Presentation()

# Load two PowerPoint documents
pres1.LoadFromFile("Sample.pptx")
pres2.LoadFromFile("Template.pptx")

# Get the slide master of the second presentation
master = pres2.Masters.get_Item(0)

# Add the slide master to the first presentation
index = pres1.Masters.AppendSlide(master)

# Apply the slide master to the first presentation
pres1.Slides.get_Item(0).Layout = pres1.Masters.get_Item(index).Layouts.GetByType(SlideLayoutType.Title)
for i in range(1, pres1.Slides.Count):
    pres1.Slides.get_Item(i).Layout = pres1.Masters.get_Item(index).Layouts.GetByType(SlideLayoutType.TitleAndObject)

# Save the first presentation
pres1.SaveToFile("output/CopySlideMaster.pptx", FileFormat.Pptx2013)
pres1.Dispose()
pres2.Dispose()

Python: Create, Modify, and Copy Slide Master in PowerPoint Presentations

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.

Slide titles play a crucial role in PowerPoint presentations because they can assist the audience in quickly grasping the topics or key points of each slide. When working with PowerPoint documents, users often encounter the need to update or extract slide titles for various purposes. For example, they may need to modify titles to reflect new content or extract titles to perform tasks such as summarizing or analyzing presentation content. Knowing how to programmatically update or extract slide titles can greatly save time and effort, particularly when dealing with extensive presentations. In this article, we will demonstrate how to update and extract slide titles in PowerPoint PPTX or PPT documents 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

Update Slide Titles in PowerPoint in Python

The title of a slide can be updated using the ISlide.Title property. The detailed steps are as follows.

  • Create a Presentation instance.
  • Load a PowerPoint PPTX or PPT document using Presentation.LoadFromFile() method.
  • Get a specific slide of the document using Presentation.Slides[index] property.
  • Update the title of the slide using ISlide.Title property.
  • Save the result document using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
ppt = Presentation()
# Load a PowerPoint document
ppt.LoadFromFile("Water Of Life.pptx")

# Get the second slide
slide = ppt.Slides[1]

# Update the title of the second slide
slide.Title = "Updated Title"

# Save the result document
ppt.SaveToFile("UpdateSlideTitle.pptx", FileFormat.Pptx2016)
ppt.Dispose()

Python: Update or Extract Slide Titles in PowerPoint

Extract All Slide Titles from PowerPoint in Python

To extract all slide titles from a PowerPoint document, you first need to iterate through all slides in the document and all shapes on each slide. Then identify shapes with placeholder types like Title, CenteredTitle, or Subtitle. After that retrieve the text content from the identified shapes using the IAutoShape.TextFrame.Text property. The detailed steps are as follows.

  • Create a Presentation instance.
  • Load a PowerPoint PPTX or PPT document using Presentation.LoadFromFile() method.
  • Create a list to store the extracted titles.
  • Iterate through all slides in the document.
  • For each slide, iterate through all shapes on it.
  • Identify shapes with placeholder types such as Title, CenteredTitle, or Subtitle.
  • Typecast the identified shapes to IAutoShape object.
  • Retrieve the text content of the identified shapes using the IAutoShape.TextFrame.Text property and append them to the list.
  • Save the content of the list to a text file.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Load a PowerPoint document
ppt = Presentation()
ppt.LoadFromFile("Water of Life.pptx")

# Create a list to store the extracted slide titles
titles = []

# Iterate through all slides in the document
for slide in ppt.Slides:
    # Iterate through all shapes on each slide
    for shape in slide.Shapes:
        # Find the shapes with placeholder types such as Title, CenteredTitle, or Subtitle
        if shape.Placeholder is not None and shape.Placeholder.Type in [PlaceholderType.Title, PlaceholderType.CenteredTitle, PlaceholderType.Subtitle]:
            # Typecast the shape to IautoShape object
            auto_shape = shape if isinstance(shape, IAutoShape) else None
            if auto_shape is not None:
                # Add the text of the shape to the titles list
                titles.append(auto_shape.TextFrame.Text)

# Save the extracted slide titles to a text file
with open("AllTitles.txt", "w") as file:
    file.write("Extracted titles:\n")
    file.write("\n".join(titles))

ppt.Dispose()

Python: Update or Extract Slide Titles 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.

Working with multiple PowerPoint presentations at the same time can be a daunting task, often resulting in a less-than-ideal presentation experience. However, there is a solution that can streamline this process and ensure seamless transitions throughout the presentation. By combining multiple PowerPoint files into a single cohesive presentation, presenters can eliminate the need to repeatedly open different files, saving time and effort. While manually copying slides can be arduous and time-consuming, Python offers a swift and efficient solution. This article is going to show how to leverage Spire.Presentation for Python to merge PowerPoint presentations effortlessly through Python programs.

Install Spire.PDF 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: How to Install Spire.Presentation for Python on Windows

Merging PowerPoint Presentations and Retain Their Designs

Merging PowerPoint presentations can be accomplished by reading slides from one presentation and adding them to another presentation. During the process of adding to the target presentation, developers can use Presentation.Slides.AppendBySlide(ISlide) method to add slides and retain the original design of the slides.

The detailed steps are as follows:

  • Create two instances of Presentation class.
  • Load two PowerPoint presentations using Presentation.LoadFromFile() method.
  • Iterate through each slide in the second presentation and add them to the first presentation while keeping their design using Presentation.Slides.AppendBySlide() method.
  • Save the first presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *
from spire.presentation.common import *

# Create two instances of Presentation class
pres1 = Presentation()
pres2 = Presentation()

# Load two presentation files
pres1.LoadFromFile("Sample1.pptx")
pres2.LoadFromFile("Sample2.pptx")

# Iterate through the slides of the second presentation
for slide in pres2.Slides:
    # Add each slides to the first presentation and keep the original design
    pres1.Slides.AppendBySlide(slide)

# Save the first presentation
pres1.SaveToFile("output/MergePresentations.pptx", FileFormat.Pptx2016)
pres1.Dispose()
pres2.Dispose()

Python: Merge PowerPoint Presentations

Merging PowerPoint Presentations with Consistent Design

Developers can also use Presentation.Slides.AppendByMaster(slide Islide, master IMasterSlide) method to insert slides into the target presentation and change the design of the slides to the design of the target presentation. This allows for merging presentations and ensuring a consistent design.

The detailed stops are as follows:

  • Create two instances of Presentation class.
  • Load two PowerPoint presentations using Presentation.LoadFromFile() method.
  • Iterate through each slide in the second presentation and add them to the first presentation while changing their design to the design of the first presentation using Presentation.Slides.AppendByMaster() method.
  • Save the first presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *
from spire.presentation.common import *

# Create two instances of Presentation class
pres1 = Presentation()
pres2 = Presentation()

# Load two presentation files
pres1.LoadFromFile("Sample1.pptx")
pres2.LoadFromFile("Sample2.pptx")

# Iterate through each slide in the second presentation
for slide in pres2.Slides:
    # Add each slide to the first presentation
    pres1.Slides.AppendByMaster(slide, pres1.Masters[0])

# Save the first presentation
pres1.SaveToFile("output/MergePresentationsDesign.pptx", FileFormat.Pptx2016)
pres1.Dispose()
pres2.Dispose()

Python: Merge PowerPoint Presentations

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.

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.

Managing document properties in PowerPoint is an essential aspect of presentation creation. These properties serve as metadata that provides important information about the file, such as the author, subject, and keywords. By being able to add, retrieve, or remove document properties, users gain control over the organization and customization of their presentations. Whether it's adding relevant tags for easy categorization, accessing authorship details, or removing sensitive data, effectively managing document properties in PowerPoint ensures seamless collaboration and professionalism in your slide decks.

In this article, you will learn how to add, read, and remove document properties in a PowerPoint file in Python by using the Spire.Presentation for Python library.

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 commands.

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

Prerequisite Knowledge

Document properties can be divided into two types: standard document properties and custom document properties.

  • Standard document properties are pre-defined properties that are commonly used across various PowerPoint presentations. Some examples of standard document properties include title, author, subject, keywords and company. Standard document properties are useful for providing general information and metadata about the presentation.
  • Custom document properties are user-defined properties that allow you to add specific information to a PowerPoint presentation. Unlike standard document properties, custom properties are not predefined and can be tailored to suit your specific needs. Custom properties usually provide information relevant to your presentation that may not be covered by the default properties.

Spire.Presentation for Python offers the DocumentProperty class to work with both standard document properties and custom document properties. The standard document properties can be accessed using the properties like Title, Subject, Author, Manager, Company, etc. of the DocumentProperty class. To add or retrieve custom properties, you can use the set_Item() method and the GetPropertyName() method of the DocumentProperty class.

Add Document Properties to a PowerPoint File in Python

To add or change the standard document properties, you can assign values to the DocumentProperty.Title proerpty, DocumentProperty.Subject property and other similar properties. To add custom properties to a presentation, use the DocumentProperty.set_Item(name: str, value: SpireObject) method. The detailed steps are as follows.

  • Create a Presentation object.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Get the DocumentProperty object.
  • Add standard document properties to the presentation by assigning values to the Title, Subject, Author, Manager, Company and Keywords properties of the object.
  • Add custom properties to the presentation using set_Item() of the object.
  • Save the presentation to a PPTX file using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
presentation = Presentation()

# Load a PowerPoint document
presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.pptx")

# Get the DocumentProperty object
documentProperty = presentation.DocumentProperty

# Set built-in document properties
documentProperty.Title = "Annual Sales Presentation"
documentProperty.Subject = "Company performance and sales strategy"
documentProperty.Author = "John Smith"
documentProperty.Manager = "Sarah Johnson"
documentProperty.Company = "E-iceblue Corporation"
documentProperty.Category = "Business"
documentProperty.Keywords = "sales, strategy, performance"
documentProperty.Comments = "Please review and provide feedback by Friday"

# Add custom document properties
documentProperty.set_Item("Document ID", Int32(12))
documentProperty.set_Item("Authorized by", String("Product Manager"))
documentProperty.set_Item("Authorized Date", DateTime(2024, 1, 10, 0, 0, 0, 0))

# Save to file
presentation.SaveToFile("output/Properties.pptx", FileFormat.Pptx2019)
presentation.Dispose()

Python: Add, Read, or Remove Document Properties in PowerPoint

Read Document Properties of a PowerPoint File in Python

The DocumentProperty.Title and the similar properties are not only used to set standard properties but can return the values of standard properties as well. Since the name of a custom property is not constant, we need to get the name using the DocumentProperty.GetPropertyName(index: int) method. And then, we're able to get the property's value using the DocumentProperty.get_Item(name: str) method.

The steps to read document properties of a PowerPoint file are as follows.

  • Create a Presentation object.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Get the DocumentProperty object.
  • Get the standard document properties by using the Title, Subject, Author, Manager, Company, and Keywords properties of the object.
  • Get the count of the custom properties, and iterate through the custom properties.
  • Get the name of a specific custom property by its index using DocumentProperty.GetPropertyName() method.
  • Get the value of the property using DocumentProperty.get_Item() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
presentation = Presentation()

# Load a PowerPoint document
presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Properties.pptx")

# Get the DocumentProperty object
documentProperty = presentation.DocumentProperty

# Get the built-in document properties
print("Title: " + documentProperty.Title)
print("Subject: " + documentProperty.Subject)
print("Author: " + documentProperty.Author)
print("Manager : " + documentProperty.Manager)
print("Company: " + documentProperty.Company)
print("Category: " + documentProperty.Category)
print("Keywords: " + documentProperty.Keywords)
print("Comments: " + documentProperty.Comments)

# Get the count of the custom document properties
count = documentProperty.Count

# Iterate through the custom properties
for i in range(count):

    # Get the name of a specific custom property
    customPropertyName = documentProperty.GetPropertyName(i)

    # Get the value of the custom property
    customPropertyValue = documentProperty.get_Item(customPropertyName)

    # Print the result
    print(customPropertyName + ": " + str(customPropertyValue))

Python: Add, Read, or Remove Document Properties in PowerPoint

Remove Document Properties from a PowerPoint File in Python

Removing a standard property means assigning an empty string to a property like DocumentProperty.Title. To remove the custom properties, Spire.Presentation provides the DocumentProperty.Remove(name: str) method. The following are the steps to remove document properties from a PowerPoint file in Python.

  • Create a Presentation object.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Get the DocumentProperty object.
  • Set the Title, Subject, Author, Manager, Company, and Keywords properties of the object to empty strings.
  • Get the count of the custom properties.
  • Get the name of a specific custom property by its index using DocumentProperty.GetPropertyName() method.
  • Remove the custom property using DocumentProperty.Remove() method.
  • Save the presentation to a PPTX file using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a Presentation object
presentation = Presentation()

# Load a PowerPoint document
presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Properties.pptx")

# Get the DocumentProperty object
documentProperty = presentation.DocumentProperty

# Set built-in document properties to empty strings
documentProperty.Title = ""
documentProperty.Subject = ""
documentProperty.Author = ""
documentProperty.Manager = ""
documentProperty.Company = ""
documentProperty.Category = ""
documentProperty.Keywords = ""
documentProperty.Comments = ""

# Get the count of the custom document properties
i = documentProperty.Count
while i > 0:

    # Get the name of a specific custom property
    customPropertyName = documentProperty.GetPropertyName(i - 1)

    # Remove the custom property
    documentProperty.Remove(customPropertyName)
    i = i - 1

# Save the presentation to a different pptx file
presentation.SaveToFile("Output/RemoveProperties.pptx",FileFormat.Pptx2019)

Python: Add, Read, or Remove Document Properties 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.

In PowerPoint, sections are a powerful tool for organizing and managing slides. By dividing slides into different sections, you can better organize content, navigate through your presentation, and present information in a more structured manner. This article will demonstrate how to add and remove sections in a PowerPoint presentation using Spire.Presentation for Python.

Install Spire.PDF 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

Add a Section at the End of a PowerPoint in Python

Spire.Presentation for Python provides the Presentation.SectionList.Append(section_name) method to add a section at the end of a presentation. Here are the specific steps to perform this operation:

  • Create a Presentation class instance.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Add a section at the end using the Presentation.SectionList.Append() method.
  • Save the document using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a new presentation object
presentation = Presentation()

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

# Append a new section
presentation.SectionList.Append("New Section")

# Save the presentation
presentation.SaveToFile("AddSection.pptx", FileFormat.Pptx2013)

# Dispose of the presentation object
presentation.Dispose()

Python: Add or Remove Sections in PowerPoint

Insert a Section Before a Specified Section in Python

You can also use the Presentation.SectionList.Insert(index, section_name) method to insert a new section before a specific section. Here are the detailed steps:

  • Create a Presentation class instance.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Insert a new section before a specific section using the Presentation.SectionList.Insert() method, where index is the position of the specific section.
  • Save the document using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a new presentation object
presentation = Presentation()

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

# Insert a new section before the second section
presentation.SectionList.Insert(1," New Section")

# Save the presentation
presentation.SaveToFile("AddSection.pptx", FileFormat.Pptx2013)

# Dispose of the presentation object
presentation.Dispose()

Python: Add or Remove Sections in PowerPoint

Add a Section Before a Specified Slide in Python

You can also use the Presentation.SectionList.Add(section_name, slide) method to insert a new section before a specific slide. Here are the detailed steps:

  • Create a Presentation class instance.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Insert a new section before a specific slide using the Presentation.SectionList.Add() method
  • Save the document using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a new presentation object
presentation = Presentation()

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

# Get the second slide
slide=presentation.Slides[1]

# Add a new section before the second slide
presentation.SectionList.Add("New Section",slide)

# Save the presentation
presentation.SaveToFile("AddSection.pptx", FileFormat.Pptx2013)

# Dispose of the presentation object
presentation.Dispose()

Python: Add or Remove Sections in PowerPoint

Remove a Section from a PowerPoint in Python

If you don't need a specific section, you can simply remove it using the Presentation.SectionList.RemoveAt(index_to_remove) method. Please note that removing a section does not delete the slides within that section. Here are the steps to delete a specific section while preserving its slides:

  • Create a Presentation class instance.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Remove a specific section using the Presentation.SectionList.RemoveAt(index_to_remove) method, which takes an integer index as a parameter. You can also remove all sections using the Presentation.Slides.RemoveAll() method.
  • Save the document using Presentation.SaveToFile() method.
  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create a new presentation object
presentation = Presentation()

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

# Remove the second section
presentation.SectionList.RemoveAt(1);

# # Remove all sections
# presentation.SectionList.RemoveAll();

# Save the presentation
presentation.SaveToFile("RemoveSection.pptx", FileFormat.Pptx2013)

# Dispose of the presentation object
presentation.Dispose()

Python: Add or Remove Sections 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.

Setting an appropriate background is a crucial step when creating visually captivating and impactful PowerPoint presentations. The background serves as the foundation upon which your content is displayed, and choosing the right background can greatly enhance the overall aesthetic and effectiveness of your slides. Whether you are presenting at a business meeting, educational seminar, or social event, a well-designed background can engage your audience and effectively convey your message. In this article, we will explain how to set background color or picture for PowerPoint slides 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

Set a Background Color for a PowerPoint Slide in Python

Adding a background color for a PowerPoint slide is very simple. You just need to set the fill mode of the slide's background as a solid fill and then set a color for the slide’s background. The detailed steps are as follows.

  • Create an object of the Presentation class.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specific slide using Presentation.Slides[index] property.
  • Access the background of the slide using ISlide.SlideBackground property.
  • Set the type of the slide's background as a custom type using SlideBackground.Type property.
  • Set the fill mode of the slide’s background as a solid fill using SlideBackground.Fill.FillType property.
  • Set a color for the slide’s background using SlideBackground.Fill.SolidColor.Color property.
  • Save the result presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *

# Create a Presentation object
ppt = Presentation()
# Load a PowerPoint presentation
ppt.LoadFromFile("Input.pptx")

# Get the first slide
slide = ppt.Slides[0]

# Access the background of the slide
background = slide.SlideBackground

# Set the type of the slide's background as a custom type
background.Type = BackgroundType.Custom
# Set the fill mode of the slide's background as a solid fill
background.Fill.FillType = FillFormatType.Solid
# Set a color for the slide's background
background.Fill.SolidColor.Color = Color.get_PaleTurquoise()

# Save the result presentation
ppt.SaveToFile("Solidbackground.pptx", FileFormat.Pptx2013)
ppt.Dispose()

Python: Set Background Color or Picture for PowerPoint Slides

Set a Gradient Background for a PowerPoint Slide in Python

Adding a gradient background is a little complex. You need to set the fill mode of the slide’s background as a gradient fill and then set the gradient stops and colors. The detailed steps are as follows.

  • Create an object of the Presentation class.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specific slide using Presentation.Slides[index] property.
  • Access the background of the slide using ISlide.SlideBackground property.
  • Set the type of the slide's background as a custom type using SlideBackground.Type property.
  • Set the fill mode of the slide’s background as a gradient fill using SlideBackground.Fill.FillType property.
  • Set gradient stops and colors for the slide’s background using SlideBackground.Fill.Gradient.GradientStops.AppendByColor() method.
  • Set the shape type and angle for the gradient fill.
  • Save the result presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *

# Create a Presentation object
ppt = Presentation()
# Load a PowerPoint presentation
ppt.LoadFromFile("Input.pptx")

# Get the first slide
slide = ppt.Slides[0]

# Access the background of the slide
background = slide.SlideBackground

# Set the type of the slide's background as a custom type
background.Type = BackgroundType.Custom

# Set the fill mode of the slide's background as a gradient fill
background.Fill.FillType = FillFormatType.Gradient

# Set gradient stops and colors
background.Fill.Gradient.GradientStops.AppendByColor(0.1, Color.get_LightCyan())
background.Fill.Gradient.GradientStops.AppendByColor(0.7, Color.get_LightSeaGreen())

# Set the shape type of the gradient fill
background.Fill.Gradient.GradientShape = GradientShapeType.Linear
# Set the angle of the gradient fill
background.Fill.Gradient.LinearGradientFill.Angle = 45

# Save the result presentation
ppt.SaveToFile("Gradientbackground.pptx", FileFormat.Pptx2013)
ppt.Dispose()

Python: Set Background Color or Picture for PowerPoint Slides

Set a Background Picture for a PowerPoint Slide in Python

To add a background picture for a PowerPoint slide, you need to set the fill mode of the slide's background as a picture fill, then add a picture to the image collection of the presentation and set it as the slide’s background. The detailed steps are as follows:

  • Create an object of the Presentation class.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specific slide using Presentation.Slides[index] property.
  • Access the background of the slide using ISlide.SlideBackground property.
  • Set the type of the slide's background as a custom type using SlideBackground.Type property.
  • Set the fill mode of the slide’s background as a picture fill using SlideBackground.Fill.FillType property.
  • Add an image to the image collection of the presentation using Presentation.Images.AppendStream() method.
  • Set the image as the slide’s background using SlideBackground.Fill.PictureFill.Picture.EmbedImage property.
  • Save the result presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *

# Create a Presentation object
ppt = Presentation()
# Load a PowerPoint presentation
ppt.LoadFromFile("Input.pptx")

# Get the first slide
slide = ppt.Slides[0]

# Access the background of the slide
background = slide.SlideBackground

# Set the type of the slide's background as a custom type
background.Type = BackgroundType.Custom

# Set the fill mode of the slide's background as a picture fill
background.Fill.FillType = FillFormatType.Picture

# Add an image to the image collection of the presentation
stream = Stream("background.jpg")
imageData = ppt.Images.AppendStream(stream)
# Set the image as the slide's background
background.Fill.PictureFill.FillType = PictureFillType.Stretch
background.Fill.PictureFill.Picture.EmbedImage = imageData

# Save the result presentation
ppt.SaveToFile("Picturebackground.pptx", FileFormat.Pptx2013)
ppt.Dispose()

Python: Set Background Color or Picture for PowerPoint Slides

Set a Background for a Slide Master in PowerPoint in Python

If you don't wish to set backgrounds for slides one by one, you can set a background for the slide master, then all slides using the same slide master will be applied with the background automatically. The following steps show how to set a solid background color for a slide master.

  • Create an object of the Presentation class.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specific slide master using Presentation.Masters[index] property.
  • Access the background of the slide master using IMasterSlide.SlideBackground property.
  • Set the type of the slide master's background as a custom type using SlideBackground.Type property.
  • Set the fill mode of the slide master's background as a solid fill using SlideBackground.Fill.FillType property.
  • Set a color for the slide master's background using SlideBackground.Fill.SolidColor.Color property.
  • Save the result presentation using Presentation.SaveToFile() method.
  • Python
from spire.presentation import *

# Create a Presentation object
ppt = Presentation()
# Load a PowerPoint presentation
ppt.LoadFromFile("Input.pptx")

# Get the first slide master
slideMaster = ppt.Masters[0]

# Access the background of the slide master
background = slideMaster.SlideBackground

# Set the type of the slide master's background as a custom type
background.Type = BackgroundType.Custom

# Set the fill mode of the slide master's background as a solid fill
background.Fill.FillType = FillFormatType.Solid
# Set a color for the slide master's background
background.Fill.SolidColor.Color = Color.get_PeachPuff()

# Save the result presentation
ppt.SaveToFile("AddBackgroundToSlideMaster.pptx", FileFormat.Pptx2013)
ppt.Dispose()

Python: Set Background Color or Picture for PowerPoint Slides

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.

page