How to Apply Animation Effect to Text and Shapes in PowerPoint in Java
Tags: java, powerpoint, animation
Published: 2021-06-11 04:00:30

---
title: How to Apply Animation Effect to Text and Shapes in PowerPoint in Java
published: true
description: This article shows how to apply animation effect to text and shapes in PowerPoint in Java.
tags: Java, PowerPoint, Animation
//cover_image: https://direct_url_to_image.jpg
---
Animation can help to make a PowerPoint document more dynamic and attractive. You can animate both text or shapes on a PowerPoint slide. In this article, I am going to show you how to apply animation effect to text and shapes in PowerPoint programmatically in Java using Free Spire.Presentation for Java library.
##Installation##
If you use maven, you need to specify the dependencies for Free Spire.Presentation for Java library in your project’s pom.xml file.
```java
<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>
```
For non-maven projects, download Free Spire.Presentation for Java pack from [this website](https://www.e-iceblue.com/Download/presentation-for-java-free.html), unzip the package and add Spire.Presentation.jar in the lib folder into your project as a dependency.
##Apply animation effect to shapes##
Free Spire.Presentation for Java supports **151** animation effects, you can see the full list of animation effects in AnimationEffectType enum. The following example shows how to add boomerang effect to a shape.
```java
import com.spire.presentation.*;
import com.spire.presentation.drawing.animation.*;

import java.awt.geom.Rectangle2D;

public class AnimateShapes {
    public static void main(String []args) throws Exception {
        //Create a Presentation instance
        Presentation ppt = new Presentation();
        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Add a shape to slide
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.CUBE, new Rectangle2D.Double(250, 150, 150, 150));

        //Add animation effect to the shape
        AnimationEffect effect= slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.BOOMERANG);

        //Save the document
        ppt.saveToFile("AddAnimationToShape.pptx", FileFormat.PPTX_2013);
    }
}
```
Output:
![Animate Shape](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wsmnmww3ajjmevte8zhv.png) 
##Apply animation effect to text##
Animation effect can also be added to text. The following example shows how to add animation effect to a particular paragraph in a shape.
```java
import com.spire.presentation.*;
import com.spire.presentation.drawing.animation.AnimationEffect;
import com.spire.presentation.drawing.animation.AnimationEffectType;

import java.awt.geom.Rectangle2D;

public class AnimateText {
    public static void main(String []args) throws Exception {
        //Create an instance of presentation document
        Presentation ppt = new Presentation();

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Add a shape to the slide
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Double(250, 150, 250, 100));

        //Add text to the shape
        shape.appendTextFrame("This example shows how to apply animation to text in PPT document.");

        //Apply animation effect to the first paragraph in the shape
        AnimationEffect animation = shape.getSlide().getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.FLOAT);
        animation.setStartEndParagraphs(0, 0);

        //Save the document
        ppt.saveToFile("AddAnimationToText.pptx", FileFormat.PPTX_2013);
    }
}
```
Output:
![Animate Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/24ohg4ya14uv2rybgssb.png)