Extracting Text and Images from PPT Files Using Python-pptx

Setting Up the Python Environment

First, verify whether Python 3 is installed on your machine. Open a terminal and run:

python3

If Python 3 is installed, you will see the Python interactive shell. Type exit() and press Enter to exit.

If Python 3 is not installed, you can install it using one of the following methods:

Cloning the Project

Clone the powerpoint-extractor repository using Git:

git clone git@github.com:2TallTyler/powerpoint-extractor.git

Installing Dependencies

The project depends on the python-pptx library. Install it using pip with a mirror for faster download:

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple python-pptx

After installation, verify the installled packages with:

pip3 list

Configuring PyCharm

Open the cloned project in PyCharm. You may notice that the Python interpreter is not configured, causing import errors.

To fix this, click on "Add Python Interpreter", enable "Inherit global site-packages", and confirm the correct path to the Python 3 executable. Click OK to finish.

Core Code Overview

The main script, extract.py, contains the following logic:

for eachfile in glob.glob(self.input_dir + os.sep + "*.pptx"):
    ppt = Presentation(eachfile)
    print("* " + eachfile)
    presentation_count += 1
    self.cur_image_index = 1

    name = self.generate_image_name_part(eachfile)

    # Iterate over each slide
    for page, slide in enumerate(ppt.slides):
        # Collect all text from the slide into a single string
        text = ''
        for shape in slide.shapes:
            if shape.has_text_frame and shape.text.strip():
                text += os.linesep
                text += shape.text

        # Collect images from the slide
        self.cur_slide_images = []
        for shape in slide.shapes:
            self.drill_for_images(shape, page + 1, name)

        # Prepare image list as a comma-separated string
        image_list = ''
        if len(self.cur_slide_images) > 0:
            image_list = ','.join(self.cur_slide_images)

        # Write to CSV: filename, slide number, text, notes, images
        writer.writerow([eachfile, page + 1, text, slide.notes_slide.notes_text_frame.text, image_list])

This code performs the following steps:

  • Iterates over all PPTX files in the input directory.
  • Loads each presentation and loops through its slides.
  • Extracts text from each slide (including text boxes) and collects all images.
  • Writes a CSV row for each slide, containing the filename, slide number, text, speaker notes, and a list of extracted images.

Running the Project

  1. Place a target PPTX file into the input directory.
  2. Click the "Run" button in PyCharm, or execute the script directly from the terminal:
python3 extract.py

After execution, extracted images are saved to the images folder, and a text.csv file is generated with the extracted data.

And that's it—a simple yet effective way to extract content from PowerPoint files using Python.

Tags: python python-pptx ppt image extraction Text Extraction

Posted on Mon, 31 Aug 2026 16:34:19 +0000 by RobertPaul