Read the complete article on how to extract text from PowerPoint presentations using Java: https://blog.aspose.com/2021/07/28/extract-text-from-powerpoint-files-using-java/
Last active
July 29, 2021 06:52
-
-
Save aspose-com-gists/14f529c17523ba866f7c984424a22d77 to your computer and use it in GitHub Desktop.
Extract Text from PowerPoint Presentations in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instatiate PresentationEx class that represents a PPTX file | |
Presentation pptxPresentation = new Presentation("presentation.pptx"); | |
//Get an Array of ITextFrame objects from the first slide | |
ITextFrame[] textFrames = SlideUtil.getAllTextFrames(pptxPresentation, true); | |
//Loop through the Array of TextFrames | |
for (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()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instatiate PresentationEx class that represents a PPTX file | |
Presentation pptxPresentation = new Presentation("presentation.pptx"); | |
//Get an Array of ITextFrame objects from the first slide | |
ITextFrame[] textFramesSlideOne = SlideUtil.getAllTextBoxes(pptxPresentation.getSlides().get_Item(1)); | |
//Loop through the Array of TextFrames | |
for (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()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment