Skip to main content

Create, Load, and Save PowerPoint Presentations

  • 3 minutes to read

The DevExpress Presentation API allows you to:

  • Create new PowerPoint presentations
  • Load presentations from streams or byte arrays
  • Save presentations in different PowerPoint formats

Supported presentation formats:

  • PPTX
  • PPTM
  • POTX
  • POTM

Create a Presentation

Use the parameterless Presentation() constructor to create a new PPTX presentation.

import com.devexpress.docs.presentation.*;

// Create a presentation.
try(Presentation presentation = new Presentation()) {

    // The presentation contains an empty slide by default.
    Slide slide = presentation.getSlides().getFirst();

    // Your implementation goes here.
}

Load a Presentation from a Stream

Tip

Configure security loading limits and options before you load a presentation to protect your application from malicious or malformed files.

Refer to the following help topic for additional information: Secure Presentation Processing.

Use the Presentation(InputStream) constructor to load a presentation from a stream:

import com.devexpress.docs.presentation.*;
import java.io.FileInputStream;

try(
    // Open a stream to an existing presentation file.
    FileInputStream inputStream = new FileInputStream("my-presentation.pptx");

    // Load the presentation from the input stream.
    Presentation presentation = new Presentation(inputStream)
) {
    // Your implementation goes here.
}

If you know the document format, specify it explicitly to improve load performance.

import com.devexpress.docs.presentation.*;
import java.io.FileOutputStream;
import java.nio.file.*;

// Load a PPTM presentation from a file into memory.
try(Presentation presentation =
                new Presentation(Files.readAllBytes(
                        Path.of("my-presentation.pptm")), DocumentFormat.PPTM)
) {
    // Your implementation goes here.
}

The following code snippet loads a presentation from a ReadableByteChannel:

import com.devexpress.docs.presentation.Presentation;

import java.nio.channels.*;
import java.nio.file.*;

// Open a readable byte channel to an existing presentation file.
try (ReadableByteChannel channel =
             FileChannel.open(Path.of("my-presentation.pptx"),
                     StandardOpenOption.READ);
     Presentation presentation =
             new Presentation(channel, DocumentFormat.PPTX)) {

    // Work with the presentation here.
}

Warning

If you try to load an empty or corrupted presentation file, or a file in an unsupported format, the API throws a PresentationUnsupportedFormatException.

Load a Presentation from a Byte Array

Use the Presentation(Byte[]) or Presentation(Byte[], DocumentFormat) constructor to load a presentation from a byte array:

import com.devexpress.docs.presentation.*;
import java.io.FileOutputStream;
import java.nio.file.*;

// Load a PPTX presentation from a file into memory.
// Document format is explicitly specified as PPTX to improve load performance.
try (Presentation presentation =
             new Presentation(Files.readAllBytes(
                     Path.of("my-presentation.pptx")), DocumentFormat.PPTX)) {

        // Your implementation goes here.
}

Warning

If you try to load an empty or corrupted presentation file, or a file in an unsupported format, the API throws a PresentationUnsupportedFormatException.

Save the Presentation

Tip

Sanitize a presentation before you save it if the output file may contain private, hidden, or other sensitive content.

Refer to the following help topic for additional information: Sanitize Presentation Content

Use the saveDocument method to save the presentation to a file/stream or byte array.

The default output format is PPTX. Use the saveDocument method with the documentFormat parameter to specify the output presentation format.

import com.devexpress.docs.presentation.*;
import java.io.FileOutputStream;
import java.nio.file.*;

try (Presentation presentation = new Presentation()) {
    // Ensure the output directory path is resolved.
    Path outputDir = Path.of("output");
    Files.createDirectories(outputDir);

    try (FileOutputStream fileStream = new FileOutputStream(
            outputDir.resolve("my-presentation-copy.pptm").toFile())) {

        // Save the presentation to a PPTM file.
        presentation.saveDocument(fileStream, DocumentFormat.PPTM);
    }
}

The following code snippet loads a presentation from a file, optionally modifies it, and then saves it back to disk as a PPTX file.

// Load an existing presentation.
try (Presentation presentation = new Presentation(
        Files.readAllBytes(Path.of("input/presentation.pptx")))) {

    // Modify the presentation.

    // Save the presentation to a new file.
    Path outputDir = Path.of("output");
    Files.createDirectories(outputDir);

    try (WritableByteChannel writableByteChannel =
                 FileChannel.open(outputDir.resolve("presentation.pptx"),
                         StandardOpenOption.CREATE,
                         StandardOpenOption.WRITE,
                         StandardOpenOption.TRUNCATE_EXISTING)) {

        presentation.saveDocument(writableByteChannel, DocumentFormat.PPTX);
    }
}

Next Steps

Configure Slide Masters and Layouts
Learn how to configure slide masters and layouts.
Manage Slides
Learn how to create and customize slides in a presentation.