# Python を使用して PPTX ファイルからテキストと画像を抽出する

> Python ソース コードを解析して PPTX プレゼンテーション。

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



## Python 経由で PPTX プレゼンテーションからテキストを抽出

プレゼンテーション全体からテキストをスキャンするには、SlideUtil クラスによって公開される [GetAllTextFrames](https://reference.aspose.com/slides/python-net/aspose.slides.util/slideutil/) 静的メソッドを使用します。以下のコードは、マスター スライドを含むプレゼンテーションからテキストと書式設定情報をスキャンします。

### Python を使用して PPTX プレゼンテーションからテキストを抽出しています

```py

import aspose.slides as slides

#Instatiate Presentation class that represents a PPTX file
with slides.Presentation("pres.pptx") as pptxPresentation:
    # Get an Array of ITextFrame objects from all slides in the PPTX
    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 経由で PPTX からテキストを抽出する方法

PPTX ファイルを解析する手順は次のとおりです。

プレゼンテーションのインスタンスで PPTX を読み込みます

PPTX 内のすべてのスライドから TextFrame オブジェクトの配列を取得します

TextFrames の配列をループする

現在の TextFrame の段落をループします

現在の段落の部分をループする

現在の部分のテキストを取得する

## サポートされているその他の解析形式
