# 使用 Python 從 PPT 文件中提取文本和圖像

> Python源代碼解析PPT Presentation。

Source: https://products.aspose.com/slides/zh-hant/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 對像數組

遍歷 TextFrames 數組

循環遍歷當前 TextFrame 中的段落

遍歷當前段落中的部分

獲取當前部分的文本

## 其他支持的解析格式
