Read PowerPoint Files in C# and VB.NET

GemBox.Presentation supports reading PowerPoint presentations in C# and VB.NET from a file path or a stream. This functionality is exposed through the PresentationDocument.Load static method overloads.

The following example demonstrates how to read a PowerPoint presentation from a file path, iterate over all Shape, TextParagraph and TextRun elements, and output text for all TextRun elements with font-weight information to the Console output.

Screenshot

Reading Screenshot

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

Upload your file (Drag files here)

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 = PresentationDocument.Load("Reading.pptx");
17
18        StringBuilder sb = new StringBuilder();
19
20        Slide slide = presentation.Slides[0];
21
22        foreach (Shape shape in slide.Content.Drawings.OfType<Shape>())
23        {
24            sb.AppendFormat("Shape ShapeType={0}:", shape.ShapeType);
25            sb.AppendLine();
26
27            foreach (TextParagraph paragraph in shape.Text.Paragraphs)
28            {
29                foreach (TextRun run in paragraph.Elements.OfType<TextRun>())
30                {
31                    bool isBold = run.Format.Bold;
32                    string text = run.Text;
33
34                    sb.AppendFormat("{0}{1}{2}", isBold ? "<b>" : "", text, isBold ? "</b>" : "");
35                }
36
37                sb.AppendLine();
38            }
39
40            sb.AppendLine("----------");
41        }
42
43        Console.WriteLine(sb.ToString());
44    }
45}
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 = PresentationDocument.Load("Reading.pptx")
14
15        Dim sb As New StringBuilder()
16
17        Dim slide As Slide = presentation.Slides(0)
18
19        For Each shape As Shape In slide.Content.Drawings.OfType(Of Shape)
20            sb.AppendFormat("Shape ShapeType={0}:", shape.ShapeType)
21            sb.AppendLine()
22
23            For Each paragraph As TextParagraph In shape.Text.Paragraphs
24                For Each run As TextRun In paragraph.Elements.OfType(Of TextRun)
25                    Dim isBold As Boolean = run.Format.Bold
26                    Dim text As String = run.Text
27
28                    sb.AppendFormat("{0}{1}{2}", If(isBold, "<b>", ""), text, If(isBold, "</b>", ""))
29                Next
30
31                sb.AppendLine()
32            Next
33
34            sb.AppendLine("----------")
35        Next
36
37        Console.WriteLine(sb.ToString())
38
39    End Sub
40
41End Module

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