Animation is a feature provided by Microsoft PowerPoint that makes presentations more engaging and fun. It can also be used to highlight different elements on the slide to draw the audience’s attention. You can add animations to text, shapes, and other elements on the slides. In this article, you will learn how to apply animation to text in PowerPoint files using C++.

C++ API for Applying Animation to Text in PowerPoint Files

We will use the Aspose.Slides for C++ API to apply text animation in PowerPoint files. It is a robust and feature-rich API for creating, reading, and modifying PowerPoint PPTX/PPT files without requiring Microsoft PowerPoint to be installed. You can either install the API through NuGet or download it directly from the Downloads section.

PM> Install-Package Aspose.Slides.Cpp

Apply Animation to Text in PowerPoint Files using C++

Aspose.Slides for C++ supports over 150+ animation effects, such as Expand, Fade, Blink, Zoom, etc. Furthermore, it also provides specific animation effects such as OLEObjectShow and OLEObjectOpen. You can see the complete list of supported animation effects in the EffectType enumeration.

In order to apply animation to text in PowerPoint presentations, please follow the steps given below.

The following sample code shows how to apply an animation effect to text in PowerPoint presentations using C++.

// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation2.pptx";
const String outputFilePath = u"OutputDirectory\\ApplyTextAnimation.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Access the shape
SharedPtr<IAutoShape> autoShape = System::DynamicCast_noexcept<Aspose::Slides::IAutoShape>(presentation->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0));
// Access the paragraph
auto paragraph = autoShape->get_TextFrame()->get_Paragraphs()->idx_get(0);
// Add the effect
auto effect = presentation->get_Slides()->idx_get(0)->get_Timeline()->get_MainSequence()->AddEffect(paragraph, EffectType::Fly, EffectSubtype::Left, EffectTriggerType::OnClick);
// Save Presentation file
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

Get Animation Effects from PowerPoint Files using C++

You can retrieve the animation effects already applied to a text by following the steps given below.

The following sample code shows how to get the animation effects from a text in PowerPoint presentations using C++.

// File path
const String sourceFilePath = u"OutputDirectory\\ApplyTextAnimation.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Get the sequence
auto sequence = presentation->get_Slides()->idx_get(0)->get_Timeline()->get_MainSequence();
// Access the shape
SharedPtr<IAutoShape> autoShape = System::DynamicCast_noexcept<Aspose::Slides::IAutoShape>(presentation->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0));
// Loop through the paragraphs
for (SharedPtr<IParagraph> paragraph : autoShape->get_TextFrame()->get_Paragraphs())
{
// Get the effects
auto effects = sequence->GetEffectsByParagraph(paragraph);
if (effects->get_Length() > 0)
{
// Print to the console
Console::WriteLine(String::Format(u"Paragraph {0} has {1} effect.", paragraph->get_Text(), effects->idx_get(0)->get_Type()));
}
}

Get a Free License

In order to try the API without evaluation limitations, you can request a free temporary license.

Conclusion

In this article, you have learned how to add animation effects to text in PowerPoint presentations using C++. Furthermore, you have seen how to retrieve animation effects from text in PowerPoint presentations. Aspose.Slides for C++ provides many additional features that you can explore in detail by visiting the official documentation. In case of any questions, please feel free to reach us at our free support forum.

See Also