- 从 PowerPoint 幻灯片中提取文本
- 从 PowerPoint 演示文稿中提取文本
为了操作 PowerPoint 演示文稿,我们将使用Aspose.Slides for Java,旨在在 Java 应用程序中实现 PowerPoint 自动化功能。它还提供了一些从 PPT/PPTX 演示文稿中提取文本的简单方法。
>>你可以点击这里下载Aspose.Slides 最新版测试体验。
用 Java 从 PowerPoint 幻灯片中提取文本
以下是使用 Java 从 PowerPoint 演示文稿中的幻灯片中提取文本的步骤。
- 使用Presentation类加载演示文稿。
- 使用SlideUtil.getAllTextBoxes()方法将幻灯片中的所有文本框获取到ITextFrame数组中。
- 循环遍历每个ITextFrame并使用ITextFrame.getParagraphs()方法访问其文本。
- 从段落的每个IPortion中检索和打印文本。
以下代码示例展示了如何从 PowerPoint 幻灯片中提取文本。
//Instatiate PresentationEx class that represents a PPTX filePresentation pptxPresentation = new Presentation("presentation.pptx");//Get an Array of ITextFrame objects from the first slideITextFrame[] textFramesSlideOne = SlideUtil.getAllTextBoxes(pptxPresentation.getSlides().get_Item(1));//Loop through the Array of TextFramesfor (int i = 0; i < textFramesSlideOne.length; i++) { //Loop through paragraphs in current TextFrame for (IParagraph para : textFramesSlideOne[i].getParagraphs()) { //Loop through portions in the current Paragraph for (IPortion port : para.getPortions()) { //Display text in the current portion System.out.println(port.getText()); //Display font height of the text System.out.println(port.getPortionFormat().getFontHeight()); //Display font name of the text System.out.println(port.getPortionFormat().getLatinFont().getFontName()); } } }
从整个 PowerPoint 演示文稿中提取文本
还可以从整个 PowerPoint 演示文稿中提取文本。以下是执行此操作的步骤。
- 使用Presentation类加载演示文稿。
- 使用SlideUtil.getAllTextFrames()方法获取演示文稿中的所有文本框。
- 循环遍历每个ITextFrame并访问其段落。
- 访问段落的各个部分并打印它们的文本。
以下代码示例展示了如何从 PowerPoint 演示文稿中提取文本。
//Instatiate PresentationEx class that represents a PPTX filePresentation pptxPresentation = new Presentation("presentation.pptx");//Get an Array of ITextFrame objects from the first slideITextFrame[] textFrames = SlideUtil.getAllTextFrames(pptxPresentation, true);//Loop through the Array of TextFramesfor (int i = 0; i < textFrames.length; i++) { //Loop through paragraphs in current TextFrame for (IParagraph para : textFrames[i].getParagraphs()) { //Loop through portions in the current Paragraph for (IPortion port : para.getPortions()) { //Display text in the current portion System.out.println(port.getText()); } } }
如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。
还想要更多吗可以点击阅读【Aspose最新资源在线文库】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!