Export PowerPoint to ImageSource in WPF

The WPF Image control allows you to display images in an application. You can use the GemBox.Presentation API to convert a PowerPoint slide to an image.

With the following example, you can see how converting a presentation slide to an ImageSource instance works. You will also see how to attach the converted image to WPF's Image control.

PowerPoint slide exported to ImageSource with GemBox.Presentation
Screenshot of PowerPoint slide exported to ImageSource with GemBox.Presentation
<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Export to ImageSource Example" 
        SizeToContent="WidthAndHeight">

    <Border Margin="10" BorderBrush="Black" BorderThickness="1">
        <Image x:Name="ImageControl"/>
    </Border>

</Window>
using System.Windows;
using System.Windows.Controls;
using GemBox.Presentation;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        SetImageSource(this.ImageControl);
    }

    private static void SetImageSource(Image image)
    {
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = new PresentationDocument();

        var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        var textBox = slide.Content.AddTextBox(ShapeGeometryType.Rectangle, 2, 2, 8, 4, LengthUnit.Centimeter);
        textBox.Shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        var run = textBox.AddParagraph().AddRun("Hello World!");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Black));

        image.Source = presentation.ConvertToImageSource(SaveOptions.Image);
    }
}
Imports System.Windows
Imports System.Windows.Controls
Imports GemBox.Presentation

Class MainWindow

    Public Sub New()

        InitializeComponent()

        SetImageSource(Me.ImageControl)
    End Sub

    Private Shared Sub SetImageSource(image As Image)

        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim presentation = New PresentationDocument()

        Dim slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        Dim textBox = slide.Content.AddTextBox(ShapeGeometryType.Rectangle, 2, 2, 8, 4, LengthUnit.Centimeter)
        textBox.Shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        Dim run = textBox.AddParagraph().AddRun("Hello World!")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Black))

        image.Source = presentation.ConvertToImageSource(SaveOptions.Image)
    End Sub
End Class

See also


Next steps

GemBox.Presentation is a .NET component that enables you to read, write, edit, convert, and print presentation files from your .NET applications using one simple API.

Download Buy