Introduction
Automatically created PowerPoint slides can be of great assistance in business presentation creation, report scheduling automation, and slide consistency. It is easy for developers to create, modify, and manipulate PowerPoint files within .NET applications using IronPPT, a powerful C# framework. IronPPT allows you to add dynamic slides, layout, text, images, charts, and shapes dynamically, and even export presentations to other formats such as PDF or image. For business people, educators, and programmers seeking to generate business-grade presentations automatically, this is the ideal solution. It is demonstrated here how to incorporate the feature-rich power of IronPPT in a C# application to automatically generate professional-level PowerPoint presentations.
How to Create a PPT in C
- Set up a C# project in Visual Studio (.NET Core or .NET Framework).
- Install IronPPT via NuGet Package Manager.
- Create a new PowerPoint presentation.
- Add a slide.
- Insert text, images, or shapes.
- Save the presentation.
- Run the application to generate the PowerPoint file.
What is IronPPT?
IronPPT is a .NET control that creates, edits and processes PowerPoint presentations programmatically. It offers developers a fast means of automating PowerPoint without the Microsoft PowerPoint Interop library or Microsoft Office installed. Using IronPPT, one can create presentations, edit slides by inserting text, images, charts, and shapes, get data, and save slides as images or PDFs. Its minimal weight makes it the go-to option for C# applications in cloud, desktop, and web environments, providing a fast and efficient alternative to standard Office automation.
Features of IronPPT
Create and Modify PowerPoint Presentations
PowerPoint presentations can be programmed in code by developers or updated with IronPPT to presentations that already exist. It is simple to insert, modify, and delete slides programmatically and automate presentation generation for reports, dashboards, and business cases.
Manage Slide Contents
Text, image, shape, chart, and table insertion and positioning are facilitated by IronPPT. Insertion of business logos, graphical representation of data, or insertion of formatted text on slides is facilitated in real-time with dynamic alignment of content. Position, alignment, and font controls are facilitated by the library to provide a professional appearance.
Media Support
IronPPT provides to insert, move, resize, and arrange images. The tool accommodates several image formats like PNG, JPEG, and BMP that provide flexibility in handling media objects in PowerPoint slides. Apart from this image set, the developer can integrate multimedia objects like audio and video to present information.
Extract Slide Content
In addition to editing PowerPoint presentations, IronPPT is also a reader for reading slide texts, images, and other elements. This can be helpful for using it in situations where PowerPoint contents are going to be revised or reused, e.g., for purposes of making summaries or converting contents on slides into some other form.
Conversion to Other Forms
IronPPT also allows PowerPoint slides to be exported into other formats, such as PDF and images (PNG, JPEG). Export is utilized when presenting in a non-PowerPoint environment or when generating printable reports.
Create a New Visual Studio Project
Here are the steps to open a new visual studio project:
Open the Visual Studio IDE. Make sure you have previously installed Visual Studio on your machine before opening
Launch a New Project:
Select File, New, and then Project.
Select your preferred programming language (for example, C#) from the list on the left-hand side of the "Create a new project" box. Next, from the list of possible project templates, select the "Console App" or "Console App (.NET Core)" template. To give your project a name, please fill in the "Name" form.
Choose the project's storage location. Click "Create" to begin working on a new Console application project.
Install IronPPT in Visual Studio
To install IronPPT on a C# project, you need to install it using NuGet Package Manager in Visual Studio. To install IronPPT, do the following:
Install via Package Manager Console
Open Visual Studio and go to Tools > NuGet Package Manager > Package Manager Console.
Run the following command to install IronPPT:
Install-Package IronPPT
once the installation is completed it will be added to the c# application.
Create a PowerPoint presentation using IronPPT
Once IronPPT has been installed, you can begin to create new PowerPoint presentations. Below is a step-by-step procedure:
Create a New Presentation
To create a new presentation object using the ironPPT namespace:
using IronPpt;
// Create a new presentation
var presentation = new PresentationDocument();
Create a new Slide
To create a new presentation slide, use the below code.
// Add a blank slide
presentation.AddSlide();
Presentation is a placeholder for a file instance of PowerPoint, and AddSlide() creates a new slide with a default layout. Creating a slide is simpler because developers can create dynamic slides programmatically in batched presentations. It is only after the creation of the first slide that additional objects can be added to extend its customization with the inclusion of text, images, charts, and so on. This method is helpful in situations where dynamic reporting generation, data visualizing, or auto-PowerPoint creation is needed based on C#.
Adding Text to Slide
Slide slide = new Slide();
slide.AddText("Hello World!");
presentation.AddSlide(slide);
The C# code sample that follows shows how to use IronPPT to add and insert a slide into a PowerPoint presentation. First, an empty slide is constructed using a new Slide(), which creates a new slide object. The AddText method is then utilized to place the text "Hello World!" on the slide. Finally, the slide is added to the PowerPoint file by inserting it into the presentation using the AddSlide function. This enables programmatic slide creation and changes at runtime before the presentation is saved or exported.
Save the Presentation
After adding the text to the slide, save the PowerPoint presentation file :
// Save the presentation to a file
presentation.SaveAs("sampleppt.pptx");
This will save the modified presentation to the specified file path.
To know more about the Ironppt Documentation refer here.
Full code:
using IronPPT;
using IronPPT.Interfaces;
using IronPPT.Models;
IronPPT.License.LicenseKey = "Licence key here";
Console.WriteLine("PPT creation process started");
// Create a new presentation
var presentation = new PresentationDocument();
// Add slide object
Slide slide = new Slide();
slide.AddText("Hello World!");
presentation.AddSlide(slide);
// Export PowerPoint presentation
presentation.Save("output.pptx");
Console.WriteLine("PPT creation process ended");
The below output is generated from the above code.
Conclusion
In this tutorial, we have been able to create PowerPoint presentations dynamically with IronPPT in C#. We did the job step by step and understood how to create a project in C#, include the IronPPT library, and create a PowerPoint document from scratch. We discussed the basic features of adding slides, inserting text, images, shapes, and charts, and formatting so that the presentation would be ready. We also demonstrated how presentations in alternative modes can be exported from their source mode such as PDF and images.
Moreover, developers can enhance presentations by adding animations, transitions, and interactivity to the viewing experience. Simplifying business processes or creating report-based content is much simpler with PowerPoint presentation generation under the application of IronPPT for .NET. To know more about the IronPPT license details check here and to know more about the other ironsoftware products refer here.
Top comments (0)