Skip to main content

Slide Size and Orientation — Presentation API for Java

  • 3 minutes to read

Slide size settings define the visible area, aspect ratio, and orientation of each presentation slide when it is displayed or exported.

The DevExpress Presentation API allows you to:

  • Obtain slide size information
  • Use predefined slide formats
  • Specify slide orientation
  • Define custom slide dimensions

Obtain Slide Size and Orientation

Call the Presentation.getSlideSize() method to obtain slide size settings.

The SlideSize object exposes the following methods:

Method Description
getWidth() Returns the slide width.
getHeight() Returns the slide height.
getOrientation() Returns the slide orientation.
getType() Returns the slide size type.

The following code snippet obtains slide dimensions and orientation:

import com.devexpress.docs.presentation.*;

// Get slide dimensions.
float width = presentation.getSlideSize().getWidth();
float height = presentation.getSlideSize().getHeight();

// Get slide orientation.
SlideOrientation slideOrientation = presentation.getSlideSize().getOrientation();

Use Predefined Slide Size

The SlideSizeType enumeration contains predefined slide formats:

Slide Size Type Description
WIDESCREEN Widescreen (13.333x7.5 inches). Default presentation size.
A3_PAPER A3 paper (297 x 420 mm).
A4_PAPER A4 paper (210 x 297 mm).
B4_ISO_PAPER B4 (ISO) paper (250 x 353 mm).
B5_ISO_PAPER B5 (ISO) paper (176 x 250 mm).
BANNER Banner (8 x 1 inches).
LEDGER_PAPER Ledger paper (11 x 17 inches).
LETTER_PAPER Letter paper (8.5 x 11 inches).
ON_SCREEN On-screen show (4:3, 14 x 10.5 inches).
ON_SCREEN_16X9 On-screen show (16:9, 10 x 5.625 inches).
ON_SCREEN_16X10 On-screen show (16:10, 10 x 6.25 inches).
OVERHEAD Overhead (10 x 7.5 inches).
SLIDE_35MM 35 mm slide format (11.25 x 7.5 inches).

The following code snippet creates a presentation that uses A4 paper format:

import com.devexpress.docs.presentation.*;

// Create a presentation.
try(Presentation presentation = new Presentation()) {
    presentation.setSlideSize(new SlideSize(SlideSizeType.A4_PAPER));

    // Your additional implementation goes here.
}

Specify Slide Orientation

For predefined slide sizes, you can specify the slide orientation when you create a SlideSize object.

The SlideOrientation enumeration contains the following values:

Value Description
LANDSCAPE Horizontal orientation.
PORTRAIT Vertical orientation.

The following code snippet creates a presentation that uses A4 paper format and portrait orientation:

presentation.setSlideSize(
        new SlideSize(
                SlideSizeType.A4_PAPER,
                SlideOrientation.PORTRAIT));

Set a Custom Slide Size

Use the SlideSize(float width, float height) constructor to set custom slide dimensions. Width and height values are specified in document units.

The following code snippet creates a presentation with a custom slide size of 1600 × 900 document units:

// Specify custom slide dimensions.
presentation.setSlideSize(new SlideSize(1600, 900));

When a custom size is assigned, the SlideSize.getType() method returns CUSTOM:

// Returns SlideSizeType.CUSTOM.
SlideSizeType sizeType = presentation.getSlideSize().getType();

Scale Content for Slide Size Changes

Use the Presentation.resizeSlides(newSize, mode) method to resize all slides in a presentation to the specified size. The mode parameter specifies how to resize the slide content.

The following example resizes slides to 640 × 360 and scales the content to fit within the new slide boundaries:

package presentation;

import com.devexpress.docs.presentation.*;

import java.io.FileOutputStream;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try(Presentation presentation =
                    new Presentation(Files.readAllBytes(Path.of("Presentation.pptx")))) {

            presentation.resizeSlides(new SlideSize(640, 360), ResizeMode.ENSURE_FIT);

            Path outputDir = Path.of("output");
            Files.createDirectories(outputDir);

            try (FileOutputStream fileStream = new FileOutputStream(
                    outputDir.resolve("PresentationResized.pptx").toFile())) {

                presentation.saveDocument(fileStream);
            }
        }
    }
}

The following table lists available resize modes:

Value Description
CENTER Centers content on the resized slide.
STRETCH Stretches content to fill the resized slide.
ENSURE_FILL Scales content to fill the resized slide.
ENSURE_FIT Scales content to fit within the resized slide.
See Also