Write PowerPoint Files in C# and VB.NET

Creating presentation content programmatically with GemBox.Presentation is easy and straightforward. This is done by composing presentation elements through factory methods.

GemBox.Presentation supports writing PowerPoint presentations in C# and VB.NET to a file or a stream. This functionality is exposed through the PresentationDocument.Save method overloads.

The following example shows how to create a new presentation programmatically and how to write a PowerPoint presentation to a file.

Screenshot

Writing Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using System;
2using System.IO;
3using System.Linq;
4using System.Text;
5using GemBox.Presentation;
6using GemBox.Presentation.Tables;
7
8class Sample
9{
10    [STAThread]
11    static void Main(string[] args)
12    {
13        // If using Professional version, put your serial key below.
14        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
15
16        PresentationDocument presentation = new PresentationDocument();
17
18        Slide slide = presentation.Slides.AddNew(SlideLayoutType.Custom);
19
20        Shape shape = slide.Content.AddShape(ShapeGeometryType.RoundedRectangle, 2, 2, 8, 4, LengthUnit.Centimeter);
21        shape.Format.Fill.SetSolid(Color.FromName(ColorName.DarkBlue));
22
23        TextRun run = shape.Text.AddParagraph().AddRun("This sample shows how to write or save a new PowerPoint file with GemBox.Presentation.");
24        run.Format.Fill.SetSolid(Color.FromName(ColorName.White));
25
26        presentation.Save("Writing.pptx");
27    }
28}
1Imports System.IO
2Imports System.Text
3Imports GemBox.Presentation
4Imports GemBox.Presentation.Tables
5
6Module Samples
7
8    Sub Main()
9
10        ' If using Professional version, put your serial key below.
11        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
12
13        Dim presentation As PresentationDocument = New PresentationDocument
14
15        Dim slide As Slide = presentation.Slides.AddNew(SlideLayoutType.Custom)
16        Dim shape As Shape = slide.Content.AddShape(ShapeGeometryType.RoundedRectangle, 2, 2, 8, 4, LengthUnit.Centimeter)
17        shape.Format.Fill.SetSolid(Color.FromName(ColorName.DarkBlue))
18
19        Dim run As TextRun = shape.Text.AddParagraph().AddRun("This sample shows how to write or save a new PowerPoint file with GemBox.Presentation.")
20        run.Format.Fill.SetSolid(Color.FromName(ColorName.White))
21
22        presentation.Save("Writing.pptx")
23
24    End Sub
25
26End Module

Check next sample or find out more about GemBox.Presentation and GemBox Software.