Convert PowerPoint Presentations to Word Documents in Java

Overview

This article provides a solution for developers on converting PowerPoint and OpenDocument presentations to Word documents using Aspose.Slides and Aspose.Words. The step-by-step guide walks you through every stage of the conversion process.

Convert PowerPoint to Word

Follow the instructions below to convert a PowerPoint or OpenDocument presentation to a Word document:

  1. Download Aspose.Slides for Java and Aspose.Words for Java libraries.
  2. Add aspose-slides-x.x-jdk16.jar and aspose-words-x.x-jdk16.jar to your CLASSPATH.
  3. Use this code snippet to convert the PowerPoint to Word:
Presentation pres = new Presentation("sample.pptx");

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

for (ISlide slide : pres.getSlides()) {
    // generates a slide image as a byte array stream
    IImage image = slide.getImage(1, 1);
    ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
    image.save(imageStream, ImageFormat.Png);
    image.dispose();

    builder.insertImage(imageStream.toByteArray());

    // inserts slide's texts
    for (IShape shape : slide.getShapes()) {
        if (shape instanceof AutoShape) {
            builder.writeln(((AutoShape) shape).getTextFrame().getText());
        }
    }

    builder.insertBreak(BreakType.PAGE_BREAK);
}

doc.save("output.docx");
pres.dispose();

FAQ

What components need to be installed to convert PowerPoint and OpenDocument presentations to Word documents?

You only need to add the respective package for Aspose.Slides for Java and Aspose.Words for Java to your project. Both libraries operate as standalone APIs, and there is no requirement for Microsoft Office to be installed.

Are all PowerPoint and OpenDocument presentation formats supported?

Aspose.Slides supports all presentation formats, including PPT, PPTX, ODP, and other common file types. This ensures that you can work with presentations created in various versions of Microsoft PowerPoint.