# 通过 Java 从 ODP 文档中提取文本和图像

> 用于从 JSP/JSF 应用程序和桌面应用程序的 Java 运行时环境中的 ODP 文件中提取文本和图像的 Java 示例代码。

Source: https://products.aspose.com/slides/zh/java/parser/odp/
Updated: 2026-08-11



## 如何使用 Java 解析 ODP 文件

 为了解析 ODP 文件，我们将使用
 [Aspose.Slides for Java](https://products.aspose.com/slides/zh/java/)
 API 是一个功能丰富、功能强大且易于使用的 Java 平台解析 API。您可以直接从
 [Maven](https://repository.aspose.com/webapp/#/artifacts/browse/tree/General/repo/com/aspose/aspose-slides)
 并通过将以下配置添加到 pom.xml 将其安装在基于 Maven 的项目中。

### 存储库

```xml

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

```

### 依赖

```xml

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>26.8</version>
    <classifier>jdk16</classifier>
</dependency>
```

## 在 Java 中解析 ODP 文件的步骤

使用 [Aspose.Slides for Java](https://products.aspose.com/slides/zh/java/) API 解析基本文档只需几行代码即可完成。

通过实例化 Presentation 类加载 ODP 文件。

获取第一张幻灯片文本框架。

循环遍历每个段落部分。

获取所需的输出，如文本、字体等。

## 系统要求

 Aspose.Slides for Java 支持所有主要平台和操作系统。请确保您具有以下先决条件。

- 适用于 JSP/JSF 应用程序和桌面应用程序的 Microsoft Windows 或具有 Java 运行时环境的兼容操作系统。
- 直接从 Java 获取最新版本的 Aspose.Slides
 [Maven](https://repository.aspose.com/webapp/#/artifacts/browse/tree/General/repo/com/aspose/aspose-slides)。

### 解析 ODP 文件 - Java

```cs
//Load ODP file
Presentation odpPresentation = new Presentation("demo.odp");
try{
    //Get an Array of TextFrameEx objects from the first slide
    ITextFrame[] textFramesSlideOne = SlideUtil.getAllTextBoxes(odpPresentation.getSlides().get_Item(0));

    //Loop through the Array of TextFrames
    for (int i = 0; i < textFramesSlideOne.length; i++){
        //Loop through paragraphs in current TextFrame
        for (IParagraph para : textFramesSlideOne[0].getParagraphs()){
            //Loop through portions in the current Paragraph
            for (IPortion port : para.getPortions()){
                //Display text in the current portion
                System.out.print(port.getText());

                //Display font height of the text
                System.out.print(port.getPortionFormat().getFontHeight());

                //Display font name of the text
                System.out.print(port.getPortionFormat().getLatinFont().getFontName());
            }
        }
    }
} finally {
    if (odpPresentation != null) odpPresentation.dispose();
}
//Similarly extarcting text from the Whole Presentation
//Use getAllTextFrames(odpPresentation, true) method and Iterate through Array

```

## 关于 Aspose.Slides for Java API

 Aspose.Slides API 可用于读取、编写、操作 Microsoft PowerPoint 文档并将其转换为 PDF、XPS、HTML、TIFF、ODP 和各种其他格式。可以从头开始创建新文件并将其保存为相关支持的格式。 Aspose.Slides 是一个独立的 API，用于创建、解析或操作演示文稿、幻灯片和元素，它不依赖于 Microsoft 或 OpenOffice 等任何软件。

Files with ODP extension represent presentation file format used by OpenOffice.org in the OASISOpen standard. A presentation file is a collection of slides where each slide can comprise of text, images, formatting, animations, and other media. These slides are presented to audience in the form of slideshows with custom presentation settings. ODP files can be opened by applications that conform to the OpenDocument format (such as OpenOffice or StarOffice).

## 其他支持的解析文档

- [PPT](https://products.aspose.com/slides/zh/java/parser/ppt/) — 微软PowerPoint 97-2003
- [PPTX](https://products.aspose.com/slides/zh/java/parser/pptx/) — 打开 XML 表示格式
