PDF TOOLS

How to use C# to Create a PowerPoint Presentation

Updated August 13, 2024
Share:

From the office to the classroom, Microsoft PowerPoint is a staple. With decades of improvements, it’s an industry-standard presentation tool for a reason. However, making the most of your PowerPoint presentation can be complex and time-consuming.

In this guide, we’ll explain how you can automate the creation of a PowerPoint presentation, optimize processes, and fully utilize the program thanks to the flexibility of C# (C Sharp) and the Microsoft PowerPoint interop library.

Create a C# PowerPoint Presentation - Getting Started

  • Create a new C# Project
  • Launch a new instance of the PowerPoint program
  • Create your PowerPoint presentation, including slides, text, formatting, and other elements
  • Export project as a new file

First of all, let's learn the fundamentals of PowerPoint interop before delving into the nuances of making PowerPoint documents with C#. Developers can create presentations, add slides, add content, apply formatting, and more with the help of the PowerPoint interop library, giving you more flexibility when creating a new presentation. This way, developers can customize their presentation file to meet unique requirements and access a wealth of functions.

Creating a PowerPoint presentation in C# allows you to create reports on the fly and convert presentations to other formats. You can download interop libraries for free, but you’ll need Microsoft Office installed to create a PowerPoint presentation programmatically.

Create a New Visual Studio Project

We begin by creating a new console application project in Visual Studio. Go to File and select New Project. Choose the C# language and select Console Application. Enter your project name, choose the location you want to save it to, and hit the Next button. Select the latest .NET Framework and then Create. Once your project is up and running, it’s time to add our library.

Add Microsoft PowerPoint interop library

You can create, open, and modify your PowerPoint document directly within your C# project using the Microsoft.Office.interop.PowerPoint.Application class. Here’s what the code looks like:

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

class Program
{
   static void Main(string[] args)
   {
           // Create an instance of PowerPoint application
           PowerPoint.Application powerpointApp = new PowerPoint.Application();
           // Create powerpoint presentation
           PowerPoint.Presentation presentation = powerpointApp.Presentations.Add();
           // Customize the presentation
           // Add slides, insert content, apply formatting, etc.
           // Add a new slide
           PowerPoint.Slide slide = presentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitle);
           // Insert text into the presentation slide
           slide.Shapes[1].TextFrame.TextRange.Text = "Demo";
           slide.Shapes[2].TextFrame.TextRange.Text = "PowerPoint";
           // Add an image to the slide
           slide.Shapes.AddPicture(@"sample.png",
                                   Microsoft.Office.Core.MsoTriState.msoFalse,
                                   Microsoft.Office.Core.MsoTriState.msoCTrue,
                                   100, 100, 300, 200);
           // Save and close the presentation file
           presentation.SaveAs("Presentation.pptx");
           presentation.Close();
           // Quit PowerPoint application
           powerpointApp.Quit();
           Console.ReadKey();
   }
}
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

class Program
{
   static void Main(string[] args)
   {
           // Create an instance of PowerPoint application
           PowerPoint.Application powerpointApp = new PowerPoint.Application();
           // Create powerpoint presentation
           PowerPoint.Presentation presentation = powerpointApp.Presentations.Add();
           // Customize the presentation
           // Add slides, insert content, apply formatting, etc.
           // Add a new slide
           PowerPoint.Slide slide = presentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitle);
           // Insert text into the presentation slide
           slide.Shapes[1].TextFrame.TextRange.Text = "Demo";
           slide.Shapes[2].TextFrame.TextRange.Text = "PowerPoint";
           // Add an image to the slide
           slide.Shapes.AddPicture(@"sample.png",
                                   Microsoft.Office.Core.MsoTriState.msoFalse,
                                   Microsoft.Office.Core.MsoTriState.msoCTrue,
                                   100, 100, 300, 200);
           // Save and close the presentation file
           presentation.SaveAs("Presentation.pptx");
           presentation.Close();
           // Quit PowerPoint application
           powerpointApp.Quit();
           Console.ReadKey();
   }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

You can alter newly constructed PowerPoint presentations to make it fit your requirements. Slides, text, photos, charts, chart title, and other multimedia items may be inserted, formatting may be applied, transitions and animations may be established, and other tasks may be involved. By utilizing the features offered by the PowerPoint interop library, you may programmatically adjust different parts of the presentation.

Save your Output File

To save the PowerPoint document to a specific file location, use the SaveAs() method. To dismiss it, use the dismiss method.

Conclusion

Using C# to create PowerPoint presentations is an effective way to improve productivity, streamline processes, and save time. The Microsoft PowerPoint interop library's features may be utilized by developers to automate the production and customization of presentations, resulting in time and effort savings and professional outcomes when working with PowerPoint files.

Using this method can improve your presentation skills and help you engage your audience with visually striking slides, whether you're a presenter, educator, or business professional.

For more expansive document management and presentation creation options, explore Iron Software's range of tools, like IronPDF for PDF Manipulation and IronXL for Excel Automation. These tools integrate seamlessly with C# projects, offering enhanced functionality and streamlining your workflow.

< PREVIOUS
How to Use C# to Convert PowerPoint to Image
NEXT >
Open Source PDF Editor (Free & Paid Tools Comparison)

Ready to get started? Version: 2024.12 just released

Free NuGet Download Total downloads: 11,622,374 View Licenses >