Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
PowerPoint presentations are essential for business reports, sales pitches, academic lectures, and software-generated dashboards. However, manually creating PowerPoint slides can be tedious and time-consuming.
Wouldn't it be great if you could automate PowerPoint creation in C# without needing to download interop libraries? That’s where Iron Software's powerful PowerPoint library, IronPPT comes in. IronPPT is a powerful .NET library that allows developers to programmatically create, modify, and export PowerPoint presentations with ease without the need for the Microsoft PowerPoint interop library. Whether you need to generate slides dynamically, insert charts, or convert presentations to PDF, IronPPT provides a simple and effective solution.
Today, we’ll explore how to create PowerPoint presentations in C# using IronPPT. We’ll cover:
Let’s dive in! 🚀
Before we dive into creating presentations programmatically, let’s first set up our development environment.
To use IronPPT, install the NuGet package in your C# project:
Run the following command:
Install-Package IronPPT
Alternatively, you can install it by going to "Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution", searching for IronPPT, and clicking "Install".
Once installed, you’re ready to start creating PowerPoint presentations within our .NET Framework.
The first step in PowerPoint automation is creating a new PowerPoint file. With IronPPT, you can generate PowerPoint presentations programmatically and save them as .pptx files. By default, the generated PowerPoint file is compatible with Microsoft PowerPoint, Google Slides, and other software that supports the .pptx format. For today's example, we will create a new Visual Studio project.
So, for our first code example, we will be creating a new blank powerpoint presentation file. This will be our starting point, a simple powerpoint presentation file which we can later add text, styling, and more to.
using IronPPT;
class Program
{
static void Main()
{
// Creating a new PresentationDocument object
var ppt = new PresentationDocument();
// Save the blank file presentation
ppt.Save("example.pptx");
}
}
using IronPPT;
class Program
{
static void Main()
{
// Creating a new PresentationDocument object
var ppt = new PresentationDocument();
// Save the blank file presentation
ppt.Save("example.pptx");
}
}
Imports IronPPT
Friend Class Program
Shared Sub Main()
' Creating a new PresentationDocument object
Dim ppt = New PresentationDocument()
' Save the blank file presentation
ppt.Save("example.pptx")
End Sub
End Class
Output file
When we open the new presentation in our PowerPoint program, we can see that all it contains at this point is a single blank slide.
A PowerPoint presentation consists of multiple slides, each of which can have different layouts, text, images, and design elements. Using IronPPT, you can dynamically add slides to a presentation, modify their layout, and insert content programmatically. This is useful for automated reporting systems, dashboard exports, and presentation generation.
At this point, our PowerPoint document is just a single blank slide without any content or extra slides. So let's look at how you can begin adding slides to your PowerPoint presentation.
using IronPPT;
using IronPPT.Models;
// Loading an existing presentation file
var ppt = new PresentationDocument("output.pptx");
// Add an additional slide
ppt.AddSlide();
// Save the updated presentation
ppt.Save("output.pptx");
using IronPPT;
using IronPPT.Models;
// Loading an existing presentation file
var ppt = new PresentationDocument("output.pptx");
// Add an additional slide
ppt.AddSlide();
// Save the updated presentation
ppt.Save("output.pptx");
Imports IronPPT
Imports IronPPT.Models
' Loading an existing presentation file
Private ppt = New PresentationDocument("output.pptx")
' Add an additional slide
ppt.AddSlide()
' Save the updated presentation
ppt.Save("output.pptx")
Output
🔹 Beyond adding simple slides such as these, you can add multiple slides and modify them dynamically using IronPPT. For our example, we have only added two slides to our presentation, but you can add as many as you need.
Once you’ve added slides, the next step is to insert content. IronPPT allows you to add:
For example, you can add a title to a slide, insert an image, and position it dynamically based on your layout needs. Using IronPPT's ParagraphStyle and TextStyle classes, we can apply formatting and custom styling to the text as it's added to the slides.
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Loading an existing presentation
var ppt = new PresentationDocument("test.pptx");
// Adding simple text to the title slide
ppt.Slides[0].TextBoxes[0].AddText("Welcome to IronPPT");
// Creating a new text box on the second slide
TextBox textBox = new TextBox
{
Type = ShapeType.Rectangle,
Width = 500,
Height = 200,
Position = (100, 100)
};
ppt.Slides[1].AddChild(textBox);
// Adding a styled paragraph to the second slide
var style = new ParagraphStyle
{
Alignment = TextAlignmentTypeValues.Center,
NoBullet = true,
LineSpacing = 30,
ContextualSpacing = true
};
TextStyle textStyle = new TextStyle
{
IsBold = true,
Color = Color.Blue
};
var paragraph = new Paragraph();
paragraph.Style = style;
paragraph.AddText("Let's create some awesome presentations with IronPPT!");
paragraph.TextStyle = textStyle;
ppt.Slides[1].TextBoxes[0].AddParagraph(paragraph);
ppt.Save("example.pptx");
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Loading an existing presentation
var ppt = new PresentationDocument("test.pptx");
// Adding simple text to the title slide
ppt.Slides[0].TextBoxes[0].AddText("Welcome to IronPPT");
// Creating a new text box on the second slide
TextBox textBox = new TextBox
{
Type = ShapeType.Rectangle,
Width = 500,
Height = 200,
Position = (100, 100)
};
ppt.Slides[1].AddChild(textBox);
// Adding a styled paragraph to the second slide
var style = new ParagraphStyle
{
Alignment = TextAlignmentTypeValues.Center,
NoBullet = true,
LineSpacing = 30,
ContextualSpacing = true
};
TextStyle textStyle = new TextStyle
{
IsBold = true,
Color = Color.Blue
};
var paragraph = new Paragraph();
paragraph.Style = style;
paragraph.AddText("Let's create some awesome presentations with IronPPT!");
paragraph.TextStyle = textStyle;
ppt.Slides[1].TextBoxes[0].AddParagraph(paragraph);
ppt.Save("example.pptx");
Imports IronPPT
Imports IronPPT.Models
Imports IronPPT.Enums
' Loading an existing presentation
Private ppt = New PresentationDocument("test.pptx")
' Adding simple text to the title slide
ppt.Slides(0).TextBoxes(0).AddText("Welcome to IronPPT")
' Creating a new text box on the second slide
Dim textBox As New TextBox With {
.Type = ShapeType.Rectangle,
.Width = 500,
.Height = 200,
.Position = (100, 100)
}
ppt.Slides(1).AddChild(textBox)
' Adding a styled paragraph to the second slide
Dim style = New ParagraphStyle With {
.Alignment = TextAlignmentTypeValues.Center,
.NoBullet = True,
.LineSpacing = 30,
.ContextualSpacing = True
}
Dim textStyle As New TextStyle With {
.IsBold = True,
.Color = Color.Blue
}
Dim paragraph As New Paragraph()
paragraph.Style = style
paragraph.AddText("Let's create some awesome presentations with IronPPT!")
paragraph.TextStyle = textStyle
ppt.Slides(1).TextBoxes(0).AddParagraph(paragraph)
ppt.Save("example.pptx")
Output
In the above code, we've added new text to the existing text box on the title screen. We also created a new text box for the second slide, before adding styled paragraph text to it. This is a simple example of how you can add fully customized text to your PowerPoint presentations with IronPPT.
Next, let's add an image to our title slide and customize its size and position to have it placed as we want it on the slide.
using IronPPT;
using IronPPT.Models;
// Loading an existing presentation
var ppt = new PresentationDocument("example.pptx");
// Load the image from file and add it to the first slide
Image image = new Image();
image.LoadFromFile("example.png");
var newImage = ppt.Slides[0].AddImage(image);
// Set image size and position
newImage.Position = (150, 300);
newImage.Name = "IronPPT";
newImage.Width = 450;
newImage.Height = 200;
// Save the updated presentation
ppt.Save("output.pptx");
using IronPPT;
using IronPPT.Models;
// Loading an existing presentation
var ppt = new PresentationDocument("example.pptx");
// Load the image from file and add it to the first slide
Image image = new Image();
image.LoadFromFile("example.png");
var newImage = ppt.Slides[0].AddImage(image);
// Set image size and position
newImage.Position = (150, 300);
newImage.Name = "IronPPT";
newImage.Width = 450;
newImage.Height = 200;
// Save the updated presentation
ppt.Save("output.pptx");
Imports IronPPT
Imports IronPPT.Models
' Loading an existing presentation
Private ppt = New PresentationDocument("example.pptx")
' Load the image from file and add it to the first slide
Private image As New Image()
image.LoadFromFile("example.png")
Dim newImage = ppt.Slides(0).AddImage(image)
' Set image size and position
newImage.Position = (150, 300)
newImage.Name = "IronPPT"
newImage.Width = 450
newImage.Height = 200
' Save the updated presentation
ppt.Save("output.pptx")
Output
Beyond simple text and images, PowerPoint presentations often contain visual elements such as shapes. With IronPPT, we can add shapes to our presentation file as easily as we added the text and image before.
To demonstrate, we will create a circular shape and draw it onto the specified slide at a precise position.
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Loading an existing presentation
var ppt = new PresentationDocument("example.pptx");
// Create a circular shape with specific properties
Shape shape = new Shape
{
Name = "Circle",
Type = ShapeType.Ellipse,
Width = 300,
Height = 300,
FillColor = Color.PowderBlue,
OutlineColor = Color.Black,
Position = (180, 200)
};
// Add the shape to the second slide
ppt.Slides[1].AddShape(shape);
// Save the updated presentation
ppt.Save("example.pptx");
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Loading an existing presentation
var ppt = new PresentationDocument("example.pptx");
// Create a circular shape with specific properties
Shape shape = new Shape
{
Name = "Circle",
Type = ShapeType.Ellipse,
Width = 300,
Height = 300,
FillColor = Color.PowderBlue,
OutlineColor = Color.Black,
Position = (180, 200)
};
// Add the shape to the second slide
ppt.Slides[1].AddShape(shape);
// Save the updated presentation
ppt.Save("example.pptx");
Imports IronPPT
Imports IronPPT.Models
Imports IronPPT.Enums
' Loading an existing presentation
Private ppt = New PresentationDocument("example.pptx")
' Create a circular shape with specific properties
Private shape As New Shape With {
.Name = "Circle",
.Type = ShapeType.Ellipse,
.Width = 300,
.Height = 300,
.FillColor = Color.PowderBlue,
.OutlineColor = Color.Black,
.Position = (180, 200)
}
' Add the shape to the second slide
ppt.Slides(1).AddShape(shape)
' Save the updated presentation
ppt.Save("example.pptx")
Output
When automating PowerPoint generation, consider the following best practices:
By following these best practices, you can create high-quality, professional PowerPoint presentations while ensuring reliability and efficiency.
Automating PowerPoint creation in C# with IronPPT is a game-changer for developers who need to generate dynamic presentations quickly and efficiently. Whether you’re building an enterprise reporting system, an educational tool, or a business dashboard, IronPPT makes it easy to create and manipulate PowerPoint files programmatically in your .NET applications.
With features like slide customization, image insertion, and PDF export, IronPPT provides everything you need for seamless PowerPoint automation.
Ready to try it out? Download the free trial for IronPPT today and start building automated PowerPoint presentations in C#!