DEV Community

carlwils
carlwils

Posted on

Add Transitions to Powerpoint Slides in Java

Slide transition in PowerPoint is the the visual effect that occurs when you move move from one slide to the next during a presentation. Adding transition between slides can be useful in helping audiences distinguish between different slides while keeping them engaged. This article will share how to programmatically add transitions to different presentation slides using Free Spire.Presentation for Java.

Import JAR Dependency (2 Methods)

● Download the free library and unzip it, and then add the Spire.Presentation.jar file to your project as dependency.
● Directly add the jar dependency to your maven project by adding the following configurations to the pom.xml.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://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>
Enter fullscreen mode Exit fullscreen mode

Sample Code

The Islide.getSlideShowTransition().setType() method, Islide.getSlideShowTransition().setSoundMode() method and Islide.getSlideShowTransition().setSpeed() method offered by Free Spire.Presentation for Java allow you to set transition type, sound mode and speed for the specified slides.
The complete sample code are as follows:

import com.spire.presentation.*;
import com.spire.presentation.drawing.transition.*;

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

        //Load a PowertPoint document
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Symbolism.pptx");

        //Set the first slide transition as push and sound mode
        presentation.getSlides().get(0).getSlideShowTransition().setType(TransitionType.PUSH);
        presentation.getSlides().get(0).getSlideShowTransition().setSoundMode(TransitionSoundMode.START_SOUND);

        //Set the second slide transition as split and set the speed
        presentation.getSlides().get(1).getSlideShowTransition().setType(TransitionType.SPLIT);
        presentation.getSlides().get(1).getSlideShowTransition().setSpeed(TransitionSpeed.SLOW);

        //Save the file
        presentation.saveToFile("setTransitions.pptx", FileFormat.PPTX_2010);
        presentation.dispose();
    }
}
Enter fullscreen mode Exit fullscreen mode

Transition

Discussion (0)