Java sets the shape animation effect in PPT

This paper introduces how to add animation effects to the shapes in PPT slides by Java program code. Need to prepare ppt operation class library Spire.Presentation for Java( Download address ). Before editing the code, note that the Spire.Presentation.jar File import java program. This paper is divided into two parts
1, New PPT document, add shape, animate

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 AddAnimationToShape {
    public static void main(String[]args) throws Exception{
        //Create PowerPoint document
        Presentation ppt = new Presentation();
        //Get slide
        ISlide slide = ppt.getSlides().get(0);

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

        //Animate shapes
        slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.CHANGE_LINE_COLOR);

        //Save document
        ppt.saveToFile("AddAnimationToShape.pptx", FileFormat.PPTX_2013);

2, Load the existing PPT documents, get the shape animation effect, and set the animation effect. Here, you can do more detailed animation settings, including the type, times, duration, delay time, etc. of animation replay

import com.spire.presentation.*;
import com.spire.presentation.drawing.animation.AnimationEffect;

public class RepeatAnimation {
    public static void main(String[] args) throws Exception{
        //Load test document
        Presentation ppt = new Presentation();
        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);
        //Get the first animation in the slide
        AnimationEffect animation = slide.getTimeline().getMainSequence().get(0);

        //Set the type, times, duration and delay time of animation effect loop
        animation.getTiming().setRepeatCount(2);//Set number of repetitions
        animation.getTiming().setDuration(2);//Set duration
        animation.getTiming().setTriggerDelayTime(2);//Set delay time
        //animation.getTiming ().setAnimationRepeatType( AnimationRepeatType.UtilEndOfSlide ); / / set animation loop to the end of the slide
        //animation.getTiming ().setAnimationRepeatType( AnimationRepeatType.UtilNextClick ); / / set the animation to cycle until the next click

        //Save result document
        ppt.saveToFile("RepeatAnimation.pptx", FileFormat.PPTX_2013);


Tags: Java

Posted on Wed, 03 Jun 2020 11:38:18 -0400 by phpfreakjav