PPT TOOLS

How to use C# to Create a PowerPoint Presentation

Regan Pun
Regan Pun
March 6, 2024
Updated April 3, 2025
Share:

Introduction

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:

  • Installing IronPPT

  • Creating and saving PowerPoint files

  • Adding slides, text, images, and shapes

  • Best practices for PowerPoint automation

Let’s dive in! 🚀

Getting Started with IronPPT

Csharp Create Powerpoint Tutorial 1 related to Getting Started with IronPPT

Before we dive into creating presentations programmatically, let’s first set up our development environment.

Installing IronPPT

To use IronPPT, install the NuGet package in your C# project:

  1. Open Visual Studio.

  2. Open the Package Manager Console (Tools > NuGet Package Manager > Package Manager Console).

  3. Run the following command:

    Install-Package IronPPT
  4. Alternatively, you can install it by going to "Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution", searching for IronPPT, and clicking "Install".

    Installing IronPPT via the NuGet Package Manager screen

  5. Create a new Console Application project.

Once installed, you’re ready to start creating PowerPoint presentations within our .NET Framework.

Creating a PowerPoint Presentation in C#

1. Initializing a PowerPoint File

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
$vbLabelText   $csharpLabel

Output file

Blank presentation created using IronPPT

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.

2. Adding Slides to PowerPoint

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")
$vbLabelText   $csharpLabel

Output

Csharp Create Powerpoint Tutorial 4 related to 2. Adding Slides to PowerPoint

🔹 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.

3. Adding Text, Images, and Formatting

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.

  • Custom formatting: Fonts, colors, and alignment.

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.

Adding Text to a PowerPoint Presentation

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")
$vbLabelText   $csharpLabel

Output

Adding text and text boxes

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.

Adding an Image

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")
$vbLabelText   $csharpLabel

Output

Adding an image to the first slide

4. Customizing Slides with Shapes and Charts

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")
$vbLabelText   $csharpLabel

Output

Csharp Create Powerpoint Tutorial 7 related to 4. Customizing Slides with Shapes and Charts

Best Practices for PowerPoint Automation in C#

When automating PowerPoint generation, consider the following best practices:

1. Optimize Performance for Large Presentations

  • Limit the number of slides to prevent memory overload.

  • Use compression for images to reduce file size.

  • Avoid redundant objects to keep the presentation efficient.

2. Maintain a Consistent Design

  • Use consistent fonts and colors to maintain branding.

  • Apply slide templates to ensure a professional look.

  • Structure content logically to improve readability.

3. Handle Errors and Exceptions Gracefully

  • Implement error handling to manage invalid input.

  • Validate image paths before inserting images.

  • Ensure that exported files have the correct format and permissions.

By following these best practices, you can create high-quality, professional PowerPoint presentations while ensuring reliability and efficiency.

Conclusion

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#!

Regan Pun
Software Engineer
Regan graduated from the University of Reading, with a BA in Electronic Engineering. Before joining Iron Software, his previous job roles had him laser-focused on single tasks; and what he most enjoys at Iron Software is the spectrum of work he gets to undertake, whether it’s adding value to sales, technical support, product development or marketing. He enjoys understanding the way developers are using the Iron Software library, and using that knowledge to continually improve documentation and develop the products.
NEXT >
How to Use C# to Convert PowerPoint to Image

Ready to get started? Version: 2025.3 just released

View Licenses >