在 Java 中解析 PPT 格式
使用用于 Java API 的服务器端 Aspose.Slides 进行本机和高性能 PPT 文档解析,无需使用 Microsoft 或 Adobe PDF 等任何软件。
如何使用 Java 解析 PPT 文件
为了解析 PPT 文件,我们将使用
API 是一个功能丰富、功能强大且易于使用的 Java 平台解析 API。您可以直接从
并通过将以下配置添加到 pom.xml 将其安装在基于 Maven 的项目中。
存储库
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
依赖
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>version of aspose-slides API</version>
<classifier>jdk17</classifier>
</dependency>
在 Java 中解析 PPT 文件的步骤
使用 Aspose.Slides for Java API 解析基本文档只需几行代码即可完成。
通过实例化 Presentation 类加载 PPT 文件。
获取第一张幻灯片文本框架。
循环遍历每个段落部分。
获取所需的输出,如文本、字体等。
系统要求
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)。
解析 PPT 文件 - Java
//Load PPT file
Presentation pptPresentation = new Presentation("demo.ppt");
try{
//Get an Array of TextFrameEx objects from the first slide
ITextFrame[] textFramesSlideOne = SlideUtil.getAllTextBoxes(pptPresentation.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 (pptPresentation != null) pptPresentation.dispose();
}
//Similarly extarcting text from the Whole Presentation
//Use getAllTextFrames(pptPresentation, 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 等任何软件。Online PPT Parser Live Demos
Extract text and images from PPT documents right now by visiting our Live Demos website . The live demo has the following benefits
PPT 什么是PPT文件格式
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.
阅读更多