DEV Community

CodeSharing
CodeSharing

Posted on

Add Animations to Shapes in PowerPoint using Java

Animation can be used in Powerpoint to make the document more vivid and attractive. This article will give sample example of how to add animations to shapes in a PowerPoint document using Free Spire.Presentation for Java.

Import the Free Java API (2 Methods)
● Download the Free Spire.Presentation for Java and unzip it. Then add the Spire.Presentation.jar file to your project as dependency.

● You can also 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>3.9.0</version>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

Add Animation to Shape:

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.animation.AnimationEffectType;

import java.awt.*;

import java.awt.geom.Rectangle2D;

public class SetAnimation {
    public static void main(String[] args) throws Exception {
        //create a PowrePoint document 
        Presentation ppt = new Presentation();
        //add a slide
        ISlide slide = ppt.getSlides().get(0);

        //Add a shape to slide
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.FIVE_POINTED_STAR, new Rectangle2D.Double(50, 150, 150, 150));
        shape.getFill().setFillType(FillFormatType.SOLID);
        shape.getFill().getSolidColor().setColor(Color.orange);
        shape.getShapeStyle().getLineColor().setColor(Color.white);

        //Add animation to the shape
        slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.FADED_SWIVEL);

        //save the document
        ppt.saveToFile("AddAnimationToShape.pptx", FileFormat.PPTX_2013);
    }
}
Enter fullscreen mode Exit fullscreen mode

Alt Text

Top comments (0)