While manipulating PowerPoint documents, you may need to change the slide size so as to make your results and infographics truly pop on the screen. Here’s how to programmatically change the slide size using Java codes.
DEPENDENCY
Before running codes, you’re required to add Spire.Presentation.jar to your Java program as a dependency. You can download the product package from this link, and find the JAR file in the lib folder. If you use Maven, you can type the following codes in the pom.xml to easily import the JAR 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.free</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
Set the slide size to a predefined size
Free Spire.Presentation for Java supports changing the type of the slide size using Presentation.getSlideSize().setType() method. The following are detailed steps.
l Create a Presentation instance.
l Load a PowerPoint sample document using Presentation.loadFromFile() method.
l Set the type of the slide size as A3 using Presentation.getSlideSize().setType(SlideSizeType
value) method.
l Save the output document to another file
using Presentation.saveToFile()
method.
import com.spire.presentation.*;
public class SetToPredefinedSize {
public static void main(String[] args) throws Exception {
//Create a Presentation instance
Presentation presentation = new Presentation();
//Load a PowerPoint sample document
presentation.loadFromFile("C:\\Users\\Tina\\Desktop\\sample.pptx");
//Set the type of the slide size as Screen 4x3
presentation.getSlideSize().setType(SlideSizeType.SCREEN_4_X_3);
//Save to another file
presentation.saveToFile("output/PredefinedSize.pptx", FileFormat.PPTX_2013);
}
}
Set the slide size to a
predefined size
Free Spire.Presentation for Java supports changing the type of the slide size using Presentation.getSlideSize().setType() method. The following are detailed steps.
l Create a Presentation instance.
l Load a PowerPoint sample document using Presentation.loadFromFile() method.
l Set the type of the slide size as A3 using Presentation.getSlideSize().setType (SlideSizeType
value) method.
l Save the output document to another file
using Presentation.saveToFile()
method.
import com.spire.presentation.*;
import java.awt.*;
public class CustomizeSlideSize {
public static void main(String[] args) throws Exception {
//Create a Presentation instance
Presentation presentation = new Presentation();
//Load a PowerPoint sample document
presentation.loadFromFile("C:\\Users\\Tina\\Desktop\\sample.pptx");
//Set the slide size type as Custom
presentation.getSlideSize().setType(SlideSizeType.CUSTOM);
//Set the width value and height value
presentation.getSlideSize().setSize(new Dimension(800,400));
//Save to another file
presentation.saveToFile("output/CustomSize.pptx", FileFormat.PPTX_2013);
}
}