Java: Change the Slide Size in PowerPoint

The slide size is one of the important aspects of the visual design of PowerPoint presentations. It influences the aspect ratio and dimensions of the presentation and can have a significant impact on the overall appearance and atmosphere of the presentation. If the default slide size does not meet the visual design requirements or does not match the size of the screen showing the presentation, it is necessary to change the size of the slides to another preset size or customize a slide size. This article will demonstrate how to change the slide size of PowerPoint presentations through Java programs using Spire.Presentation for Java.

Install Spire.Presentation for Java

First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>9.3.1</version>
    </dependency>
</dependencies>
    

Change the Slide Size to a Preset Size

Spire.Presentation for Java provides the Presentation.getSlideSize().setType() method to change the slide size to a preset size. The detailed steps are as follows:

  • Create an object of Presentation class.
  • Load a PowerPoint presentation using Presentation.loadFromFile() method.
  • Change the slide type of the presentation using Presentation.getSlideSize().setType() method.
  • Save the presentation using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;

public class changeSlideSizePreset {
    public static void main(String[] args) throws Exception {
        //Create an object of Presentation class
        Presentation pt = new Presentation();

        //Load a presentation file
        pt.loadFromFile("Sample.pptx");

        //Change the slide size of the presentation to A4
        pt.getSlideSize().setType(SlideSizeType.A4);

        //Save the presentation file
        pt.saveToFile("A4Size.pptx", FileFormat.AUTO);
        pt.dispose();
    }
}

Java: Change the Slide Size in PowerPoint

Change the Slide Size to a Custom Size

Customizing the size of slides requires changing the slide size type to custom. After that, the Presentation.getSlideSize().setSize() method can be used to customize the slide size. The detailed steps are as follows:

  • Create an object of Presentation class.
  • Load a PowerPoint presentation using Presentation.loadFromFile() method.
  • Change the slide size type to custom using Presentation.getSlideSize().setType() method.
  • Customize the slide size using Presentation.getSlideSize().setSize() method.
  • Save the presentation using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSize;
import com.spire.presentation.SlideSizeType;

import java.awt.*;

public class changeSlideSizeCustom {
    public static void main(String[] args) throws Exception {
        //Create an object of Presentation class
        Presentation pt = new Presentation();

        //Load a PowerPoint presentation
        pt.loadFromFile("Sample.pptx");

        //Change the slide size type to custom
        pt.getSlideSize().setType(SlideSizeType.CUSTOM);

        //Set the slide size
        pt.getSlideSize().setSize(new Dimension(600, 600));

        //Save the presentation file
        pt.saveToFile("CustomSize.pptx", FileFormat.AUTO);
        pt.dispose();
    }
}

Java: Change the Slide Size in PowerPoint

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.