Working with Fonts of PowerPoint PPT using Python

PowerPoint allows you to customize the fonts used in your presentations. Setting fonts in PowerPoint presentations may help you create a more coherent and effective design by improving the visual appeal, clarity, and readability of your presentation. This tutorial will demonstrate how to work with the fonts of PowerPoint PPT slides in Python. We will go through how to manage the default, custom, and embedded fonts of a PPT/PPTX presentations.

Installing Python PowerPoint package

To manage the fonts of a PowerPoint presentation programmatically in Python, we will use a Python PowerPoint package, which allows developers to add, read, replace, substitute, and remove the fonts of a presentation without using Microsoft PowerPoint.

Please download or install the package from PyPI using the pip command given below:

pip install aspose-slides

Specify Default Fonts for Rendering PPT/PPTX in Python

In this section, you’ll learn how to set default fonts for rendering a presentation to PDF, XPS, or thumbnails. We will set the DefaultRegular font and DefaultAsian font for use as default fonts. Follow the steps below to set the default fonts for rendering a presentation in Python.

  1. First, create an instance of LoadOptions class.
  2. Then, set the DefaultRegularFont and DefaultAsianFont properties of the LoadOptions class.
  3. After that, load the PPT/PPTX file using Presentation class.
  4. Finally, generate the slide thumbnail, PDF, and XPS to verify the results.

The following code sample shows how to specify default fonts for rendering a presentation in Python.

Python: Using Custom Fonts in PPT/PPTX Presentation

The Aspose.Slide PowerPoint Python package allows you to load custom fonts for your PPT/PPTX presentations. To learn it, please follow the steps below for loading custom fonts from an external folder for PowerPoint PPT/PPTX using Python. Suppose we have a 28_Days_Later.ttf font file in the folder

  1. Call the static method LoadExternalFonts of FontsLoader class to load fonts folder path.
  2. Then, render the presentation.
  3. Finally, clear the cache of the FontsLoader class.

The following code snippet shows how to use custom fonts in PPT/PPTX presentations using Python.

After running the code, the 28 Days Later fonts will be available for use in your PowerPoint presentation like the following screenshot:

Using Custom Fonts in PPT/PPTX Presentation

Add Embedded Fonts in PowerPoint PPT/PPTX using Python

Let’s learn how to add embedded fonts in a PPT/PPTX presentation. Please follow the steps below.

  1. First, load the PPT file using Presentation class.
  2. Then, obtain all available fonts using get_fonts() method of fonts_manager class.
  3. After that, get embedded fonts using get_embedded_fonts() method of fonts_manager class.
  4. Loop through all fonts and check if they exist in embedded fonts. If do not exist, add them using add_embedded_font(font, slides.export.EmbedFontCharacters.ALL) method of fonts_manager.
  5. Finally, save the presentation.

The following code snippet shows how to add embedded fonts in PPT/PPTX presentations using Python.

Python Tutorial: Change Fonts in PowerPoint PPT using Python

So far, we have discussed various ways to add/insert fonts. This section shows how to change fonts in a PowerPoint presentation. Suppose, we have used Arial font in the PPT file. Let’s replace it with Times New Roman. Please follow the steps below.

  1. First, load the PowerPoint presentation.
  2. Then, load the font that will be replaced.
  3. After that, load the new font.
  4. Replace the font.
  5. Finally, save the modified presentation as a PPTX file.

The following code snippet shows how to change fonts in PPT/PPTX presentations using Python.

Get a Free License

You can get a free temporary license to try the API without evaluation limitations.

Summing Up

To sum up, we hope you have learned how to work with the fonts of a PowerPoint PPT/PPTX using Python. We have discussed various ways of adding and using fonts. Besides, we have described how to change or replace fonts in a PowerPoint presentation.

You may visit the documentation to learn more about the Python PowerPoint library.

Please stay tuned at conholdate.com for regular updates.

Ask a Question

You can let us know your questions or queries on our forum.

See Also