C# Slide Element Tutorial - IronPPT
IronPPT is a robust PowerPoint library designed to help .NET C# developers seamlessly integrate the ability to create, read, and edit PowerPoint presentations into their applications. In the context of a PowerPoint presentation, slides are the foundational elements that structure and organize the content.
Quickstart: Insert text into a new or existing slideThis example shows how effortlessly you can add text to a slide with IronPPT. In just a couple of lines, either insert into the first slide if it exists or create one, then save - fast setup, minimal fuss.
-
1Install IronPPT with NuGet Package Manager
-
2Copy and run this code snippet.
var doc = new IronPPT.PresentationDocument(); var text = doc.Slides.Count > 0 ? doc.Slides[0].AddText("Quick Option") : doc.AddSlide(new IronPPT.Models.Slide()).AddText("Quick Option"); doc.Save("quick.pptx");C# -
3Deploy to test on your live environment
Start using IronPPT in your project today with a free trial
Table of Contents
- Add Text
- Text Content (Add, Append & Remove)
- Set Styling (Font Family & Size, Color, Bold & Italic, Strikethrough, Underline)
- Add Image
- Load Image (File & FileStream)
- Set Dimensions & Angle (Width & Height)
- Set Position
- Add Shape
- Set Shape Type
- Set Dimensions (Width & Height)
- Set Fill & Outline Color
- Set Position
Add Text
Text Content
Whether you're creating a new presentation or editing an existing one, text management tools give you full control over text placement and formatting, allowing you to design slides that convey your message clearly and professionally.
using IronPPT;
using IronPPT.Models;
// Create a new PowerPoint presentation
var document = new PresentationDocument();
// Ensure there is at least one slide to work with
if (document.Slides.Count == 0)
{
document.Slides.Add(new Slide());
}
// Add text to the first slide
var text = document.Slides[0].AddText("Hello");
// Append text to the existing text on the slide
text.Text += " There!";
// Check if there is any text element to remove from the first slide
if (document.Slides[0].Texts.Count > 0)
{
document.Slides[0].Texts[0].Remove();
}
// Export the PowerPoint presentation with the specified file name
document.Save("addText.pptx");
Set Styling
Styling text enables you to customize its visual appearance by defining attributes like font size, color, style, strikethrough, and underline. Applying these styles enhances the text's presentation and improves the overall look of the document.
using IronPPT;
using IronPPT.Models; // Ensure the library is available
using IronPPT.Enums;
// Create a new presentation document
var document = new PresentationDocument();
// Define and customize the text style
var textStyle = new TextStyle
{
IsBold = true, // Text is bold
IsItalic = true, // Text is italic
Color = Color.Blue, // Text color is blue
Strike = StrikValue.SingleStrike, // Text is single struck-off
Outline = true, // Text has an outline
NoProof = true, // Disables proofing for the text
Spacing = 10.0, // Text spacing is set to 10
Underline = new Underline
{
LineValue = UnderlineValues.Single, // Single underline
Color = Color.Red // Underline color is red
},
Languages = "en-US", // Text language is set to U.S. English
SpecVanish = false, // Text does not vanish when special formatting is applied
};
// Create text content and apply the defined style
var text = new Text("Hello World"); // Instantiate text with a string
text.TextStyle = textStyle; // Apply the defined style to the text
// Add a new slide if none exist
if (document.Slides.Count == 0)
{
document.Slides.Add(new Slide()); // Add a new slide to the document
}
// Add the styled text to the first slide
document.Slides[0].AddText(text); // Add the newly created text object to the first slide
// Save the presentation document to a file
document.Save("textStyle.pptx"); // Save the document with the filename "textStyle.pptx"
Add Images
Adjust image settings for optimal display. Proper configuration ensures images are visually appealing and appropriately suited to their context.
using IronPPT;
using IronPPT.Models;
using System.Drawing;
// This script demonstrates the creation of a PowerPoint presentation using the IronPPT library.
// An image is added to the presentation, its properties are modified, and then the presentation is saved.
// Create a new PowerPoint presentation
var document = new PresentationDocument();
// Create a new Image object and load an image file.
var image = new Image();
image.LoadFromFile("sample.png");
// Add the image to the first slide (index 0) of the presentation.
var newImage = document.AddImage(image, 0);
// Set the properties of the added image.
// Position property is set using a Point object, which holds X and Y coordinates.
newImage.Position = new Point(200, 200); // Set image position on the slide
newImage.Angle = 45; // Set the rotation angle of the image
newImage.Name = "new image"; // Assign a descriptive name to the image
newImage.Width = 150; // Set the width of the image in pixels
newImage.Height = 150; // Set the height of the image in pixels
// Export the PowerPoint presentation to a file named "addImage.pptx"
document.Save("addImage.pptx");Imports IronPPT
Imports IronPPT.Models
Imports System.Drawing
' This script demonstrates the creation of a PowerPoint presentation using the IronPPT library.
' An image is added to the presentation, its properties are modified, and then the presentation is saved.
' Create a new PowerPoint presentation
Private document = New PresentationDocument()
' Create a new Image object and load an image file.
Private image = New Image()
image.LoadFromFile("sample.png")
' Add the image to the first slide (index 0) of the presentation.
Dim newImage = document.AddImage(image, 0)
' Set the properties of the added image.
' Position property is set using a Point object, which holds X and Y coordinates.
newImage.Position = New Point(200, 200) ' Set image position on the slide
newImage.Angle = 45 ' Set the rotation angle of the image
newImage.Name = "new image" ' Assign a descriptive name to the image
newImage.Width = 150 ' Set the width of the image in pixels
newImage.Height = 150 ' Set the height of the image in pixels
' Export the PowerPoint presentation to a file named "addImage.pptx"
document.Save("addImage.pptx")Add Shapes
Easily add and customize shapes in your presentation by defining their type, dimensions (width and height), fill and outline colors, and position on the slide.
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Load a PowerPoint presentation.
// The PresentationDocument is assumed to represent an entire PPTX file loaded from disk.
var document = new PresentationDocument("output.pptx");
// Configure a new shape.
// Shape is assumed to be a model object representing drawable elements on a slide.
Shape shape = new Shape
{
Name = "triangle",
Type = ShapeType.Triangle,
Width = 100,
Height = 100,
FillColor = new Color("#444444"),
OutlineColor = Color.Black,
// Position is set via the Position property, which accepts an (x, y) tuple.
// It's important that these coordinates are valid for display on the slide.
Position = (200, 200)
};
// Add the shape to the first slide in the presentation.
// Slides[0] refers to the first slide in the collection. Ensure a slide exists at this index.
document.Slides[0].AddShape(shape);
// Export the modified PowerPoint presentation.
// Saves the changes to a new file, ensuring the original presentation is not overwritten.
document.Save("addShape.pptx");
Frequently Asked Questions
What is IronPPT used for in C# development?
IronPPT is a powerful library for C# developers that allows seamless integration for creating, reading, and editing PowerPoint presentations within .NET applications.
How can I add text to a PowerPoint slide using IronPPT?
You can add text to a PowerPoint slide with IronPPT by using the 'AddText' method on a slide object, either by appending it to an existing slide or creating a new slide using IronPPT library methods.
How do I apply styling to text in a PowerPoint presentation using IronPPT?
Styling can be applied to text in IronPPT by defining attributes such as font size, color, and style through the 'TextStyle' object, which can then be applied to your text elements within a slide.
Can IronPPT be used to add images to PowerPoint slides?
Yes, IronPPT can be used to add images to PowerPoint slides. It allows you to load images from files, adjust their position, dimensions, and even apply rotations for a customized presentation.
How does IronPPT manage shape insertion in presentations?
IronPPT facilitates shape insertion by allowing developers to define shape types, dimensions, and colors, as well as position them precisely on slides, enhancing visual content dynamically.
What are the basic steps to create a new presentation with IronPPT?
To create a new presentation, instantiate a 'PresentationDocument', add slides as needed, and use the provided methods to insert text, images, and shapes. Saving your document will generate a .pptx file.
Is it possible to modify existing slides using IronPPT?
Yes, IronPPT allows modification of existing slides by accessing them through the document's slide collection, where you can add or edit text, images, and shapes.
Does IronPPT support text proofing and language settings?
IronPPT supports disabling text proofing and allows specifying the language for text formatting, giving developers more control over text presentation properties.
How does IronPPT enhance text management in PowerPoint presentations?
IronPPT enhances text management through features that allow full control over text placement, formatting, styling, and styling attributes, making presentations clear and professional.
What file formats does IronPPT output?
IronPPT outputs presentations in the .pptx file format, compatible with Microsoft PowerPoint and other presentation software supporting this format.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.