Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 29, 2021 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/14f529c17523ba866f7c984424a22d77 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/14f529c17523ba866f7c984424a22d77 to your computer and use it in GitHub Desktop.
Extract Text from PowerPoint Presentations in Java
//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());
}
}
}
//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