Articles in this section
Category / Section

How to create a PowerPoint Presentation file in C#

2 mins read

The following steps demonstrate how to create a simple PowerPoint presentation in a Windows forms application using Presentation library.

Step 1: Create a new Windows Forms application. Name it as GettingStarted.

Step 2: Install Presentation assemblies with NuGet

In Visual Studio, select Tools > NuGet Package Manager > Package Manager Console and execute the below command for the project.

install-package Syncfusion.Presentation.Base

Step 3: Add a new button in the form editor.

Step 4: Include the below code snippet in the click event of the button in Form.cs, to create a PowerPoint presentation and save it as a file.

//Creates a new instance of PowerPoint Presentation
IPresentation presentation = Presentation.Create();
 
//Adds a slide to the PowerPoint Presentation
ISlide firstSlide = presentation.Slides.Add(SlideLayoutType.Blank);
 
//Adds a textbox in a slide by specifying its position and size
IShape textShape = firstSlide.AddTextBox(100, 75, 756, 200);
 
//Adds a paragraph into the textShape
IParagraph paragraph = textShape.TextBody.AddParagraph();
 
//Set the horizontal alignment of paragraph
paragraph.HorizontalAlignment = HorizontalAlignmentType.Center;
 
//Adds a textPart in the paragraph
ITextPart textPart = paragraph.AddTextPart("Hello Presentation");
 
//Applies font formatting to the text
textPart.Font.FontSize = 80;
textPart.Font.Bold = true;
 
//Adds a new paragraph with text.
paragraph = textShape.TextBody.AddParagraph("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets");
 
//Sets the list type as bullet
paragraph.ListFormat.Type = ListType.Bulleted;
 
//Sets the bullet character for this list
paragraph.ListFormat.BulletCharacter = Convert.ToChar(183);
 
//Sets the font of the bullet character
paragraph.ListFormat.FontName = "Symbol";
 
//Sets the hanging value as 20
paragraph.FirstLineIndent = -20;
 
//Adds a new paragraph
paragraph = textShape.TextBody.AddParagraph("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico.");
 
//Sets the list type as bullet
paragraph.ListFormat.Type = ListType.Bulleted;
 
//Sets the list level as 2. Possible values can range from 0 to 8
paragraph.IndentLevelNumber = 2;
 
//Gets the image from file path
Image image = Image.FromFile(@"image.jpg");
 
// Adds the image to the slide by specifying position and size
firstSlide.Pictures.AddPicture(new MemoryStream(image.ImageData), 300, 270, 410, 250);
 
//Saves the Presentation in the given name
presentation.Save("Output.pptx");
 
//Releases the resources occupied
presentation.Close();
 

Step 5: Compile & execute the application. Now this application creates a simple PowerPoint presentation.

 

See Also:

Create a PowerPoint file in ASP.NET MVC

Create a PowerPoint file in ASP.NET

Create a PowerPoint file in Xamarin

Create a PowerPoint file in WPF

Create a PowerPoint file in UWP

Create a PowerPoint file in ASP.NET Core

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied