Animate PowerPoint Text in Python via Java

Overview

This article explains how to work with animated text in Aspose.Slides by applying animation effects to individual paragraphs and retrieving the effects already assigned to paragraphs in a text frame. It focuses on the API methods used to add paragraph-level animation and inspect existing paragraph animation effects in a presentation.

Add Animation Effects to Paragraphs

The addEffect method of the Sequence class allows you to add animation effects to a single paragraph. This sample code shows you how to add an animation effect to a single paragraph:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import EffectSubtype, EffectTriggerType, EffectType, Presentation, SaveFormat

presentation = Presentation("Presentation.pptx")
try:
    # Select the paragraph to add an effect to.
    auto_shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0)
    paragraph = auto_shape.getTextFrame().getParagraphs().get_Item(0)

    # Add a Fly animation effect to the selected paragraph.
    effect = presentation.getSlides().get_Item(0).getTimeline().getMainSequence().addEffect(paragraph, EffectType.Fly, EffectSubtype.Left, EffectTriggerType.OnClick)

    presentation.save("AnimationEffectinParagraph.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

Get Animation Effects of Paragraphs

You may want to retrieve the animation effects applied to a paragraph—for example, to apply those effects to another paragraph or shape.

Aspose.Slides for Python via Java allows you to get all the animation effects applied to paragraphs contained in a text frame (shape). This sample code shows you how to get the animation effects applied to a paragraph:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Presentation

presentation = Presentation("Presentation.pptx")
try:
    sequence = presentation.getSlides().get_Item(0).getTimeline().getMainSequence()
    auto_shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0)

    for paragraph in auto_shape.getTextFrame().getParagraphs():
        effects = sequence.getEffectsByParagraph(paragraph)

        if len(effects) > 0:
            print(f'Paragraph "{paragraph.getText()}" has {effects[0].getType()} effect.')
finally:
    presentation.dispose()

FAQ

How do text animations differ from slide transitions, and can they be combined?

Text animations control object behavior over time on a slide, while transitions control how slides change. They’re independent and can be used together; playback order is governed by the animation timeline and the transition settings.

Are text animations preserved when exporting to PDF or images?

No. PDF and raster images are static, so you’ll see a single state of the slide without motion. To keep movement, use video or HTML export.

Do text animations work in layouts and the slide master?

Effects applied to layout/master objects are inherited by slides, but their timing and interaction with slide-level animations depend on the final sequence on the slide.