change all fonts in powerpoint without opening the file

What language is the text of the file? Run.font properties work fine for UTF-8, but there is a separate font for cursive scripts like Arabic. Access to that secondary font is not implemented in python-pptx unfortunately, but that could explain at least part of the behavior you're seeing.

For roman character text (like that we're using here), there are a couple things to check.

  1. The font in question needs to be installed on the machine PowerPoint is running on when the document is opened. Otherwise PowerPoint will substitute a font.

  2. The font (typeface) name used in the XML will not always exactly match what appears in the PowerPoint drop-down selection box. You need to give that name to python-pptx in the exact form it should appear in the XML. You may need to make an example file that works by hand, perhaps containing a single slide with a single textbox for simplicity, and then inspect the XML of that file to find the "spelling" used for that typeface by PowerPoint.

    You could do that with code like this:

    prs = Presentation("example.pptx")
    shape = prs.slides[0].shapes[0]
    print(shape._element.xml)
    

You should be able to locate the typeface name somewhere in an element like <p:rPr> or <p:defRPr>.


With Aspose.Slides for Python via .NET, you can easily change all fonts for all texts in your presentations. The following code example shows you how to do this:

import aspose.slides as slides

with slides.Presentation('example.pptx') as presentation:
    for slide in presentation.slides:
        for shape in slide.shapes:
            if isinstance(shape, slides.AutoShape):
                for paragraph in shape.text_frame.paragraphs:
                    for portion in paragraph.portions:
                        portion.portion_format.latin_font = slides.FontData('Tahoma')

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.

Aspose Slides Online Viewer can be used to view presentations without PowerPoint installed.

I work at Aspose.