Recursive AI

Create a PowerPoint presentation in C#

OneDocument is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Terminal
dotnet add package RecursiveAI.OneDocument.Presentations

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneDocument.Presentations;
using var deck = Presentation.Create();
var slide = deck.AddSlide("Title and Content");
slide.SetPlaceholderText("title", "Regions");
slide.SetPlaceholderText(1, "North grew");
deck.SaveAs("review.pptx");

Unzip the example, then dotnet run.

Writes review.pptx with one slide titled “Regions”; it prints nothing. You don’t need a template or a PowerPoint installation.

The full program

The download saves a two-slide deck, reopens it, and prints the slide count and text. All the input is in Program.cs.

C#
using RecursiveAI.OneDocument.Presentations;
 
using var deck = Presentation.Create();
var title = deck.AddSlide("Title Slide");
title.SetPlaceholderText("title", "Quarterly review");
title.SetPlaceholderText("subTitle", "Half-year results");
var content = deck.AddSlide("Title and Content");
content.SetPlaceholderText("title", "Regions");
content.SetPlaceholderText(1, "North grew\nSouth held");
deck.SaveAs("review.pptx");
 
using var saved = Presentation.Open("review.pptx");
Console.WriteLine($"Slides: {saved.Slides.Count}");
foreach (var slide in saved.Slides)
{
    foreach (var shape in slide.Shapes)
        if (!string.IsNullOrEmpty(shape.Text))
            Console.WriteLine(shape.Text);
}
Text
Slides: 2
Quarterly review
Half-year results
Regions
North grew
South held

An unknown layout name or a missing placeholder throws PresentationAuthoringException; the two layouts in this example come with Presentation.Create().

Variations

To make the second slide the first, pass its insertion index when you add it. Replace the AddSlide call for content in the full program:

C#
var content = deck.AddSlide("Title and Content", 0);

The resulting deck starts with “Regions”, followed by “Quarterly review”.

The short answer

Call Presentation.Create(), add slides by layout name, set their placeholder text, and save to a .pptx path. OneDocument supplies the layouts and writes the file itself; no PowerPoint process or input file is needed.

How do I create PowerPoint slides programmatically in C#?

Choose a layout for each slide. “Title Slide” gives the cover a title and a subtitle. “Title and Content” gives the second slide a title and a space for the update. AddSlide appends by default, so create the slides in the order you want the audience to see them. The insertion-index variation is useful when you already have slides and need to put one ahead of them.

SaveAs writes the presentation, not a PDF or an image of each slide. The text remains editable. Open review.pptx from the directory where you ran the project to see how the two layouts position it. The console output in the download checks the content that was saved; it doesn’t show the appearance or whether a long paragraph fits on the slide.

How do PowerPoint slide layouts and placeholders work?

A placeholder is a shape whose role is set by the layout, such as a title or an area for content. OneDocument uses the layout to create the slide’s placeholders. The presentation model describes where their styling and bounds come from: the slide can inherit them from its layout and master. That’s why the snippet can set the text without specifying a font size or any coordinates.

Select a text placeholder by type when its role identifies it: "title" for the title (including a centered title), or "subTitle" for the subtitle. The number 1 in the second slide is the placeholder’s layout index, not the slide number or the position of a shape in a list. On the built-in “Title and Content” layout that index identifies the content placeholder. If you change the layout, check its placeholders rather than assuming the index means the same thing.

Can I create a PowerPoint presentation from scratch without a template?

Yes. The built-in layouts let you create a new deck from text supplied by your application. Start there when you want the program to decide the number, order and content of the slides. If you already have a designed deck with slide backgrounds, branding or placeholders positioned by a designer, start with that file instead. Filling an existing template preserves the starting design rather than asking your code to recreate it.

All onedocument recipes