Set the Slide Size in PowerPoint in Java

SlideSize.setType() method is used to set or change the slide size to a predefined size like Widescreen 16x9, Overhead, A3, A4, Banner, B4, and B5. To customize the slide size, set the size type to custom, and then apply a customized width and height to slide using the SlideSize.setSize() method.

Set slide size to a predefined size

import com.spire.presentation.*;

import java.awt.geom.Rectangle2D;

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

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Set the slide size to Screen 16x9
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Add a shape to the first slide
        IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(20, 50, 500, 50));
        shape.getTextFrame().setText("This example shows you how to set slide size to Widescreen 16X9.");

        //Save to file
        presentation.saveToFile("output/PredefinedSize.pptx", FileFormat.PPTX_2013);
    }
}

Set the Slide Size in PowerPoint in Java

Customize slide size

import com.spire.presentation.*;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class CustomizeSlideSize {

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

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Set the slide size type to custom
        presentation.getSlideSize().setType(SlideSizeType.CUSTOM);

        //Set the slide size to a custom size 
        presentation.getSlideSize().setSize(new Dimension(800,400));

        //Add a shape to the first slide
        IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(20, 50, 500, 50));
        shape.getTextFrame().setText("This example shows you how to customize the slide size.");

        //Save to file
        presentation.saveToFile("output/CustomSize.pptx", FileFormat.PPTX_2013);
    }
}

Set the Slide Size in PowerPoint in Java