Introduction

Aspose.Slides FOSS for .NET provides a comprehensive set of classes for managing PowerPoint presentations entirely in C#. The library lets you create new .pptx files from scratch, load existing ones, manipulate slides and shapes, and save the result back to disk – all without installing Microsoft Office or any external dependency.

The Aspose.Slides.Foss NuGet package targets .NET 9.0 and runs identically on Windows, macOS, Linux, and Docker containers. It is released under the MIT license, so you can use it in commercial and open-source projects with no restrictions.

This post walks through the core presentation management capabilities: working with slides, building shape hierarchies, organizing text, managing tables, and saving to PPTX.


What’s Included

Creating and Loading Presentations

The Presentation class is the entry point for every operation. You can create an empty presentation, load one from a file path, or read from a stream. The class implements IDisposable, so wrapping it in a using statement ensures resources are released properly.

// Create a brand-new, empty presentation
using var pres = new Presentation();

// Load an existing file
using var existing = new Presentation("report.pptx");

The Presentation object exposes the full slide hierarchy through properties such as Slides, Masters, LayoutSlides, Sections, CommentAuthors, Images, and NotesSize.

Working with Slides

The SlideCollection returned by Presentation.Slides supports adding, cloning, inserting, reordering, and removing slides. You can clone a slide within the same presentation or across presentations while preserving or remapping layouts.

using var pres = new Presentation();

// The default presentation contains one blank slide
var firstSlide = pres.Slides[0];

// Clone the first slide and append it
pres.Slides.AddClone(firstSlide);

// Insert a clone at a specific position
pres.Slides.InsertClone(1, firstSlide);

// Remove a slide by index
pres.Slides.RemoveAt(2);

// Total slide count
int count = pres.Slides.Count;

Each Slide exposes SlideNumber, Hidden, LayoutSlide, NotesSlideManager, and Name. You can iterate the collection with foreach or convert it to an array with ToArray().

Shapes and AutoShapes

Every slide contains a ShapeCollection accessible through Slide.Shapes. The collection provides factory methods for the most common shape types.

using var pres = new Presentation();
var slide = pres.Slides[0];

// Add a rectangle AutoShape
var rect = slide.Shapes.AddAutoShape(
    ShapeType.Rectangle, 50, 50, 300, 150);

// Add a connector
var connector = slide.Shapes.AddConnector(
    ShapeType.BentConnector3, 100, 200, 200, 50);

// Reorder a shape to bring it forward
slide.Shapes.Reorder(0, rect);

// Remove all shapes
slide.Shapes.Clear();

The AddAutoShape and InsertAutoShape methods accept a ShapeType enum value plus position and size coordinates. AddConnector, InsertConnector, AddPictureFrame, and InsertPictureFrame follow the same pattern.

Text: Paragraphs and Portions

Text in a presentation lives inside a TextFrame, which contains a ParagraphCollection. Each Paragraph holds a PortionCollection of Portion objects representing individual text runs with independent formatting.

using var pres = new Presentation();
var slide = pres.Slides[0];

var shape = slide.Shapes.AddAutoShape(
    ShapeType.Rectangle, 50, 50, 400, 200);

// Access the shape's text frame
var tf = shape.TextFrame;

// Read or set the full text
tf.Text = "Hello, presentation world!";

// Work with individual paragraphs and portions
var para = new Paragraph();
var portion = new Portion("Formatted run");
para.Portions.Add(portion);
tf.Paragraphs.Add(para);

Each Portion has a PortionFormat property for controlling font, size, bold/italic, color, underline, and other character-level attributes. ParagraphFormat controls alignment, bullet style, spacing, and indentation.

Tables

Tables are added through ShapeCollection.AddTable, which accepts column widths and row heights as arrays. The returned Table object provides access to Rows, Columns, and individual Cell objects.

using var pres = new Presentation();
var slide = pres.Slides[0];

double[] colWidths = { 150, 150, 150 };
double[] rowHeights = { 40, 40, 40 };

var table = slide.Shapes.AddTable(
    50, 50, colWidths, rowHeights);

// Set text in a cell
table.Rows[0][0].TextFrame.Text = "Header 1";
table.Rows[0][1].TextFrame.Text = "Header 2";
table.Rows[0][2].TextFrame.Text = "Header 3";

// Merge cells
table.MergeCells(table.Rows[1][0], table.Rows[1][2], false);

// Style presets
table.StylePreset = TableStylePreset.MediumStyle2Accent1;

Saving Presentations

The Presentation.Save method writes the document to a file or stream. The SaveFormat enum specifies the output format. PPTX is the primary supported output format.

using var pres = new Presentation();
// ... build slides ...

// Save to a file
pres.Save("output.pptx", SaveFormat.Pptx);

// Save to a stream
using var ms = new MemoryStream();
pres.Save(ms, SaveFormat.Pptx);

// Save specific slides by index
pres.Save("subset.pptx", new[] { 1, 3 }, SaveFormat.Pptx);

You can also pass a SaveOptions object for additional control over the output.


Quick Start

Install the package via the .NET CLI:

dotnet add package aspose.slides.foss

Then create and save a minimal presentation:

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

// 1. Create a new presentation
using var pres = new Presentation();

// 2. Get the default slide
var slide = pres.Slides[0];

// 3. Add a title shape
var title = slide.Shapes.AddAutoShape(
    ShapeType.Rectangle, 50, 30, 600, 60);
title.TextFrame.Text = "Quarterly Report";

// 4. Add a content shape
var body = slide.Shapes.AddAutoShape(
    ShapeType.Rectangle, 50, 120, 600, 300);
var para = new Paragraph();
para.Portions.Add(new Portion("Revenue grew 12% year-over-year."));
body.TextFrame.Paragraphs.Add(para);

// 5. Save as PPTX
pres.Save("quarterly-report.pptx", SaveFormat.Pptx);

Supported Formats

FormatExtensionReadWrite
PPTX.pptxYesYes
PPSX.ppsxNoPlanned
PPTM.pptmNoPlanned
POTX.potxNoPlanned
ODP.odpNoPlanned
FODP.fodpNoPlanned

Note: Currently only PPTX export is implemented. Other format values exist in the SaveFormat enum for forward compatibility but are not yet functional. The Save() method always produces PPTX output regardless of the format parameter. Legacy .ppt binary format is not supported.


Open Source & Licensing

Aspose.Slides FOSS for .NET is released under the MIT license. The full source code is available on GitHub. You can use it in commercial and open-source projects, modify the code, and redistribute it without restriction. No API key, license file, or registration is required.


Getting Started