How to add animation for text boxes, shapes, and images in Presentation using C#?
Syncfusion® Essential® DocIO is a .NET PowerPoint Library used to create, read, edit, and convert PowerPoint presentations programmatically without Microsoft PowerPoint or interop dependencies. Using this library, you can add animations for text boxes, shapes, and images in presentations using C#.
Steps to add animations for text boxes, shapes, and images in presentations in C#
- Create a new C# console application project.
- Install Syncfusion.PresentationRenderer.Net.Core NuGet package as a reference to your project from NuGet.org.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering a Syncfusion® license key in your application to use the components without a trial message.
- Include the following namespace in the Program.cs file:
C#
using Syncfusion.Presentation;
- Use the following code to add animations for text boxes, shapes, and images in presentations in C#:
C#
using Syncfusion.Presentation;
// Create an instance for PowerPoint.
IPresentation pptxDoc = Presentation.Create();
// Add a blank slide to the Presentation.
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
IShape textboxShape = slide.AddTextBox(200, 50, 150, 50);
IParagraph paragraph = textboxShape.TextBody.AddParagraph();
// Add a TextPart to the paragraph.
ITextPart textPart = paragraph.AddTextPart();
// Add text to the TextPart.
textPart.Text = "Hello World!";
// Access the animation sequence to create effects.
ISequence sequence = slide.Timeline.MainSequence;
// Add bounce effect to the shape.
IEffect bounceEffect = sequence.AddEffect(textboxShape, EffectType.Bounce, EffectSubtype.None, EffectTriggerType.WithPrevious);
IShape textboxShape1 = slide.AddTextBox(200, 150, 150, 50);
// Add a paragraph to the text body of the textbox.
IParagraph paragraph1 = textboxShape1.TextBody.AddParagraph();
// Add a TextPart to the paragraph.
ITextPart textPart1 = paragraph1.AddTextPart();
// Add text to the TextPart.
textPart1.Text = "New Textbox Added";
// Access the animation sequence to create effects.
ISequence sequence1 = slide.Timeline.MainSequence;
// Add swivel effect to the shape.
IEffect bounceEffect1 = sequence1.AddEffect(textboxShape1, EffectType.Swivel, EffectSubtype.None, EffectTriggerType.WithPrevious);
FileStream pictureStream = new FileStream(@"..\..\..\Data\Image.jpeg", FileMode.Open);
// Add the picture to a slide by specifying its size and position.
IPicture picture = slide.Pictures.AddPicture(pictureStream, 200, 250, 300, 200);
// Access the animation sequence to create effects.
ISequence sequence2 = slide.Timeline.MainSequence;
// Add bounce effect to the picture.
IEffect bounceEffect2 = sequence2.AddEffect(picture as IShape, EffectType.Bounce, EffectSubtype.None, EffectTriggerType.WithPrevious);
// Save the PowerPoint Presentation as a stream.
FileStream outputStream = new FileStream(@"..\..\..\Data\Sample.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
You can download a complete working sample to add animations for text boxes, shapes, and images in presentations from GitHub.
Take a moment to peruse the documentation, where you can find basic PowerPoint Presentation processing options along with features like find and replace text, working with charts, animations, smart arts, and many more in PowerPoint Presentation, and most importantly PDF conversion with code examples.
Explore more about the rich set of Syncfusion® PowerPoint Framework features.
Conclusion
I hope you enjoyed learning about how to add animations for text boxes, shapes, and images in presentations using the ASP.NET Core Presentation library.
You can refer to our ASP.NET Core Presentation feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our ASP.NET Core Presentation example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!
See Also: