# 通過 C++ 從 PPT 文檔中提取文本和圖像

> C++ 示例代碼，用於在 Windows 32 位、Windows 64 位和 Linux 64 位的 C++ 運行時環境中從 PPT 文件中提取文本和圖像。

Source: https://products.aspose.com/slides/zh-hant/cpp/parser/ppt/
Updated: 2026-08-11



## 如何使用 C++ 解析 PPT 文件

 為了解析 PPT 文件，我們將使用
 [Aspose.Slides for C++](https://products.aspose.com/slides/zh-hant/cpp/)
 API 是一個功能豐富、功能強大且易於使用的 C++ 平台文檔解析 API。可以直接下載最新版本，直接打開
 [NuGet](https://www.nuget.org/packages/aspose.slides)
 包管理器，搜索
 **Aspose.Slides.Cpp**
 並安裝。您還可以從包管理器控制台使用以下命令。

### 命令

```cs

PM> Install-Package Aspose.Slides.Cpp

```

## 在 C++ 中解析 PPT 文件的步驟

使用 [Aspose.Slides for C++](https://products.aspose.com/slides/zh-hant/cpp/) API 解析基本文檔只需幾行代碼即可完成。

加載 PPT 文件。

獲取第一張幻燈片的 ITextFrame 對像數組。

循環遍歷 TextFrames 數組

循環遍歷當前 ITextFrame 中的段落。

循環瀏覽當前 IParagraph 中的部分。

顯示文本。

## 系統要求

 Aspose.Slides for C++ 支持所有主要平台和操作系統。請確保您具有以下先決條件。

- Microsoft Windows 或具有適用於 Windows 32 位、Windows 64 位和 Linux 64 位的 C++ 運行時環境的兼容操作系統。
- 項目中引用的 C++ DLL 的 Aspose.Slides。

### 解析 PPT 文件 - C++

```cs
// Sample file path
const String sourceFilePath = u"SourcePath\sourceFile.ppt";

// Load the PPT file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);

// Get an Array of ITextFrame objects from the first slide
System::ArrayPtr<SharedPtr<ITextFrame>> textFramesSlideOne = SlideUtil::GetAllTextBoxes(presentation->get_Slides()->idx_get(0));

// Loop through the Array of TextFrames
for (int i = 0; i get_Length(); i++){
	// Loop through paragraphs in current ITextFrame
	for (SharedPtr<IParagraph> paragraph : textFramesSlideOne[i]->get_Paragraphs()){
		// Loop through portions in the current IParagraph
		for (SharedPtr<IPortion> portion : paragraph->get_Portions()){
			// Display text
			Console::WriteLine(portion->get_Text());
		}
	}
}

```

## 關於 Aspose.Slides for C++ API

 Aspose.Slides API 可用於讀取、寫入、操作 Microsoft PowerPoint 文檔並將其轉換為 PDF、XPS、HTML、TIFF、ODP 和各種其他格式。可以從頭開始創建新文件並將其保存為相關支持的格式。 Aspose.Slides 是一個獨立的 API，用於創建、解析或操作演示文稿、幻燈片和元素，它不依賴於 Microsoft 或 OpenOffice 等任何軟件。

A file with PPT extension represents PowerPoint file that consists of a collection of slides for displaying as SlideShow. It specifies the Binary File Format used by Microsoft PowerPoint 97-2003. A PPT file can contain several different types of information such as text, bulleted points, images, multimedia and other embedded OLE objects. Microsoft came up with newer file format for PowerPoint, known as PPTX, from 2007 onwards that is based on Office OpenXML and is different from this binary file format. Several other application programs such as OpenOffice Impress and Apple Keynote can also create PPT files.

## 其他支持的解析文檔

- [ODP](https://products.aspose.com/slides/zh-hant/cpp/parser/odp/) — OpenDocument 演示格式
- [PPTX](https://products.aspose.com/slides/zh-hant/cpp/parser/pptx/) — 打開 XML 表示格式
