# 使用 Python 从 PPT 文件中提取文本和图像

> Python源代码解析PPT Presentation。

Source: https://products.aspose.com/slides/zh/python-net/parser/ppt/
Updated: 2023-05-01



## 通过 Python 从 PPT 演示文稿中提取文本

要扫描整个演示文稿中的文本，请使用 SlideUtil 类公开的 [GetAllTextFrames](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) 静态方法。下面的代码扫描演示文稿中的文本和格式信息，包括母版幻灯片。

### 使用 Python 从 PPT 演示文稿中提取文本

```py

import aspose.slides as slides

#Instatiate Presentation class that represents a PPT file
with slides.Presentation("pres.ppt") as pptxPresentation:
    # Get an Array of ITextFrame objects from all slides in the PPT
    textFramesPPTX = slides.util.SlideUtil.get_all_text_frames(pptxPresentation, True)

    # Loop through the Array of TextFrames
    for i in range(len(textFramesPPTX)):
	    # Loop through paragraphs in current ITextFrame
        for para in textFramesPPTX[i].paragraphs:
            # Loop through portions in the current IParagraph
            for port in para.portions:
			    # Display text in the current portion
                print(port.text)

    			# Display font height of the text
                print(port.portion_format.font_height)

			    # Display font name of the text
                if port.portion_format.latin_font != None:
                    print(port.portion_format.latin_font.font_name)
```

## 如何通过 Python 从 PPT 中提取文本

这些是解析 PPT 文件的步骤。

使用 Presentation 实例加载 PPT

从 PPT 中的所有幻灯片中获取 TextFrame 对象数组

遍历 TextFrame 数组

循环遍历当前 TextFrame 中的段落

遍历当前段落中的部分

获取当前部分的文本

## 其他支持的解析格式
