Make each PowerPoint page an image file in Python

This is the only feature I'm happy with when creating training materials. Converts to an image file for each PowerPoint page. I've automated the same thing in Python that opens PowerPoint and chooses File → Export → Change File Type.

I used com to operate PowerPoint, and since the file name is variously disgusting with slide 1.PNG, I converted it to slide1.png.

The PowerPoint file name to be read and the output destination are specified at the beginning of the file. Of course, it won't work unless PowerPoint is installed. If you want to try it, I think that it will work if you prepare a PowerPoint file of test.pptx for the time being.

PPT_NAME = 'test.pptx'
OUT_DIR = 'images'

All sources


import os
import glob
from comtypes import client

PPT_NAME = 'test.pptx'
OUT_DIR = 'images'

def export_img(fname, odir):
    application = client.CreateObject("Powerpoint.Application")
    application.Visible = True
    current_folder = os.getcwd()

    presentation = application.Presentations.open(os.path.join(current_folder, fname))

    export_path = os.path.join(current_folder, odir)
    presentation.Export(export_path, FilterName="png")

    presentation.close()
    application.quit()


def rename_img(odir):
    file_list = glob.glob(os.path.join(odir, "*.PNG"))
    for fname in file_list:
        new_fname = fname.replace('slide', 'slide').lower()
        os.rename(fname, new_fname)


if __name__ == '__main__':
    export_img(PPT_NAME, OUT_DIR)
    rename_img(OUT_DIR)

Recommended Posts

Make each PowerPoint page an image file in Python
Create an image with characters in python (Japanese)
File processing in Python
Image format in Python
File operations in Python
Tool to make mask image for ETC in Python
Create an image file using PIL (Python Imaging Library).
How to create an image uploader in Bottle (Python)
Quicksort an array in Python 3
Download the file in Python
Don't make test.py in Python!
Tweet with image in Python
Make a bookmarklet in Python
Make Opencv available in Python
Make python segfault in 2 lines
Image Processing Collection in Python
Make a table of multiplication of each element in a spreadsheet (Python)
Make python segfault in one line
Cut out an image with python
File / folder path manipulation in Python
Implemented image segmentation in python (Union-Find)
Save the binary file in Python
How to make a string into an array or an array into a string in Python
Linebot creation & file sharing in Python
Write an HTTP / 2 server in Python
Create an Excel file with Python3
Develop an investment algorithm in Python 2
Make standard output non-blocking in Python
Create a binary file in Python
Make python segfault in three lines
ORC, Parquet file operations in Python
Python in is also an operator
Get the formula in an excel file as a string in Python
An alternative to `pause` in Python
I tried to make an image similarity function with Python + OpenCV
Creating an exe file with Python PyInstaller: PC freezes in parallel processing
Open an Excel file in Python and color the map of Japan
Ant book in python: page 42 coin problem
Creating a simple PowerPoint file with Python
Exclusive control with lock file in Python
Make ASCII art GIF animation in Python
How to convert Python to an exe file
Convert psd file to png in Python
Quickly create an excel file with Python #python
Page cache in Python + Flask with Flask-Caching
Ant book in python: page 43 Interval scheduling
Write O_SYNC file in C and Python
Read the file line by line in Python
Read the file line by line in Python
Exclusive file access between processes in Python
How to adjust image contrast in Python
[GPS] Create a kml file in Python
Easy image processing in Python with Pillow
Image sending / receiving memo in Python (Flask)
Let's make a combination calculation in Python
Make cron-like jobs run regularly in Python
CG image quality evaluation memo in Python
[Python] Read the specified line in the file
Ant book in python: page 49 Fence Repair
Status of each Python processing system in 2020
Create a Python image in Django without a dummy image file and test the image upload