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:
Creating and saving PowerPoint files
Adding slides, text, images, and shapes
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:
Open Visual Studio.
Open the Package Manager Console (Tools > NuGet Package Manager > Package Manager Console).
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
Private 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 in our presentation file
var ppt = new PresentationDocument("output.pptx");
ppt.AddSlide();
ppt.Save("output.pptx");
using IronPPT;
using IronPPT.Models;
// Loading in our presentation file
var ppt = new PresentationDocument("output.pptx");
ppt.AddSlide();
ppt.Save("output.pptx");
Imports IronPPT
Imports IronPPT.Models
' Loading in our presentation file
Private ppt = New PresentationDocument("output.pptx")
ppt.AddSlide()
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:
Text: Titles, paragraphs, and formatted content.
Images: Logos, charts, and screenshots.
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;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument("test.pptx");
// Adding simple text to the title slide
ppt.Slides[0].TextBoxes[0].AddText("Welcome to IronPPT");
TextBox textBox = new TextBox();
textBox.Type = ShapeType.Rectangle;
textBox.Width = 500;
textBox.Height = 200;
textBox.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;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument("test.pptx");
// Adding simple text to the title slide
ppt.Slides[0].TextBoxes[0].AddText("Welcome to IronPPT");
TextBox textBox = new TextBox();
textBox.Type = ShapeType.Rectangle;
textBox.Width = 500;
textBox.Height = 200;
textBox.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
' Creating a new PresentationDocument object
Private ppt = New PresentationDocument("test.pptx")
' Adding simple text to the title slide
ppt.Slides(0).TextBoxes(0).AddText("Welcome to IronPPT")
Dim textBox As New TextBox()
textBox.Type = ShapeType.Rectangle
textBox.Width = 500
textBox.Height = 200
textBox.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 have added new text to the existing text box on the title screen. We have 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;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument();
Image image = new Image();
image.LoadFromFile("example.png");
var newImage = ppt.Slides[0].AddImage(image);
newImage.Position = (150, 300);
newImage.Name = "IronPPT";
newImage.Width = 450;
newImage.Height = 200;
ppt.Save("output.pptx");
using IronPPT;
using IronPPT.Models;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument();
Image image = new Image();
image.LoadFromFile("example.png");
var newImage = ppt.Slides[0].AddImage(image);
newImage.Position = (150, 300);
newImage.Name = "IronPPT";
newImage.Width = 450;
newImage.Height = 200;
ppt.Save("output.pptx");
Imports IronPPT
Imports IronPPT.Models
' Creating a new PresentationDocument object
Private ppt = New PresentationDocument()
Private image As New Image()
image.LoadFromFile("example.png")
Dim newImage = ppt.Slides(0).AddImage(image)
newImage.Position = (150, 300)
newImage.Name = "IronPPT"
newImage.Width = 450
newImage.Height = 200
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 specific position.
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument("example.pptx");
Shape shape = new Shape();
shape.Name = "Circle";
shape.Type = ShapeType.Ellipse;
shape.Width = 300;
shape.Height = 300;
shape.FillColor = Color.PowderBlue;
shape.OutlineColor = Color.Black;
shape.Position = (180, 200);
ppt.Slides[1].AddShape(shape);
ppt.Save("example.pptx");
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument("example.pptx");
Shape shape = new Shape();
shape.Name = "Circle";
shape.Type = ShapeType.Ellipse;
shape.Width = 300;
shape.Height = 300;
shape.FillColor = Color.PowderBlue;
shape.OutlineColor = Color.Black;
shape.Position = (180, 200);
ppt.Slides[1].AddShape(shape);
ppt.Save("example.pptx");
Imports IronPPT
Imports IronPPT.Models
Imports IronPPT.Enums
' Creating a new PresentationDocument object
Private ppt = New PresentationDocument("example.pptx")
Private shape As New Shape()
shape.Name = "Circle"
shape.Type = ShapeType.Ellipse
shape.Width = 300
shape.Height = 300
shape.FillColor = Color.PowderBlue
shape.OutlineColor = Color.Black
shape.Position = (180, 200)
ppt.Slides(1).AddShape(shape)
ppt.Save("example.pptx")
Output
When automating PowerPoint generation, consider the following best practices:
Limit the number of slides to prevent memory overload.
Use compression for images to reduce file size.
Use consistent fonts and colors to maintain branding.
Apply slide templates to ensure a professional look.
Implement error handling to manage invalid input.
Validate image paths before inserting images.
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#!