Read/Extract Text from a PowerPoint Document in Java

In this article, we will show you how to read/extract text from a PowerPoint document using Spire.Presentation for Java.

The sample PowerPoint document:

Read/Extract Text from a PowerPoint Document in Java

import com.spire.presentation.*;

import java.io.FileWriter;

public class ExtractText {
    public static void main(String[] args) throws Exception {

        //Create a Presentation instance
        Presentation ppt = new Presentation();
        //Load the PowerPoint document
        ppt.loadFromFile("Input.pptx");

        StringBuilder buffer = new StringBuilder();

        //Loop through the slides in the document and extract text
        for (Object slide : ppt.getSlides()) {
            for (Object shape : ((ISlide) slide).getShapes()) {
                if (shape instanceof IAutoShape) {
                    for (Object tp : ((IAutoShape) shape).getTextFrame().getParagraphs()) {
                        buffer.append(((ParagraphEx) tp).getText());
                    }
                }
            }
        }
        //Save text
        FileWriter writer = new FileWriter("ExtractText.txt");
        writer.write(buffer.toString());
        writer.flush();
        writer.close();
    }
}

Output:

Read/Extract Text from a PowerPoint Document in Java