Listen
Copied RSS Feed

PowerPoint

Seamless Slide Conversion: PowerPoint to Images in C#

TL;DR: Let’s see how to convert PowerPoint slides into images using Syncfusion’s .NET PowerPoint Library in C#. This guide covers converting entire presentations, individual slides, and slide ranges into images with just a few lines of code.

PowerPoint presentations are an effective tool for sharing information, but many scenarios exist where converting slides into images can be highly beneficial. Whether embedding slides into websites, creating static previews, or sharing slide content as images for better accessibility, this process can be accomplished effortlessly using the Syncfusion PowerPoint Library in C#.

This guide will demonstrate how to programmatically convert PowerPoint slides into images using Syncfusion .NET PowerPoint Library (Presentation). With just a few lines of code, you can seamlessly convert presentations into images without requiring Microsoft PowerPoint or any interop dependencies.

This PowerPoint-to-image conversion is available in multiple environments, such as:

  • Windows
  • Linux
  • macOS
  • Mobile devices
  • Docker
  • Cloud computing platforms

Let’s get started with the implementation!

Experience the magic of Syncfusion’s C# PowerPoint Library. Witness your ideas come to life with its Microsoft PowerPoint-like editing, conversion, and formatting options.

Getting started

Step 1: First, create a new C# .NET Core Console App in Visual Studio.

Step 2: Then, install the Syncfusion.PresentationRenderer.Net.Core NuGet package as a reference to the app from NuGet Gallery.

Step 3: Now, include the following namespaces in the Program.cs file.

using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;

Now, your project is ready to start converting PowerPoint slides into images.

Convert an entire PowerPoint presentation to images

Converting an entire PowerPoint presentation into images is beneficial for creating slide previews or exporting slides as standalone image files for offline sharing. The RenderAsImages method helps us to process all slides in a presentation, converting each into an image.

Refer to the following code example.

// Open the file as Stream.
using (FileStream fileStream = new FileStream(Path.GetFullPath("Template.pptx"), FileMode.Open, FileAccess.Read))
{
    // Load an existing PowerPoint presentation.
    using (IPresentation pptxDoc = Presentation.Open(fileStream))
    {
        // Initialize PresentationRenderer.
        pptxDoc.PresentationRenderer = new PresentationRenderer();
        // Convert PowerPoint to images.
        Stream[] images = pptxDoc.RenderAsImages(ExportImageFormat.Jpeg);
        // Save the images to a file.
        for (int i = 0; i < images.Length; i++)
        {
            using (Stream stream = images[i])
            {
                using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Image-" + i + ".jpg")))
                {
                    stream.CopyTo(fileStreamOutput);
                }
            }
        }
    }
}

By executing this code example, we will get the output like in the following screenshot.

Converting entire PowerPoint to images in C#

The features of Syncfusion’s PowerPoint Library are documented with clear code examples for multiple scenarios.

Convert a single slide in a PowerPoint presentation to an image

Converting a single slide to an image is ideal for scenarios where you need to highlight or share a specific slide, such as creating a featured thumbnail or sharing a key slide on social media. You can use the RenderAsImage method to convert just one slide from a presentation into an image.

Refer to the following code example.

// Open the file as Stream.
using (FileStream inputStream = new FileStream(Path.GetFullPath("Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    // Load an existing PowerPoint presentation.
    using (IPresentation pptxDoc = Presentation.Open(inputStream))
    {
        // Initialize PresentationRenderer.
        pptxDoc.PresentationRenderer = new PresentationRenderer();
        // Convert the first slide of the PowerPoint to an image.
        using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
        {
            // Save the image stream to a file.
            using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Image.jpg")))
            {
                stream.CopyTo(fileStreamOutput);
            }
        }
    }
}

By executing this code example, we will get the output like in the following screenshot.

Convert a specific range of slides in a PowerPoint presentation to images

Converting a range of slides to images helps generate previews for selected slides, share a subset of slides, or export only the most relevant presentation sections. You can iterate over a specific range of slides and convert them into images using the RenderAsImage method.

Refer to the following code example.

// Open the file as Stream.
using (FileStream inputStream = new FileStream(Path.GetFullPath("Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    // Load an existing PowerPoint presentation.
    using (IPresentation pptxDoc = Presentation.Open(inputStream))
    {
        // Initialize PresentationRenderer.
        pptxDoc.PresentationRenderer = new PresentationRenderer();
        // Loop through a specific range of slides and convert each to an image.
        for (int currentSlideIndex = 2; currentSlideIndex < pptxDoc.Slides.Count - 1; currentSlideIndex++)
        {
            using (Stream stream = pptxDoc.Slides[currentSlideIndex].ConvertToImage(ExportImageFormat.Jpeg))
            {
                // Save the image stream to a file.
                using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Image_" + currentSlideIndex + ".jpeg")))
                {
                    stream.CopyTo(fileStreamOutput);
                }
            }
        }
    }
}

Step into a world of boundlessly creative presentations with Syncfusion’s C# PowerPoint Library!

GitHub reference

For more details, refer to converting PowerPoint to images using C# GitHUb demo.

Conclusion

Thanks for reading! We’ve seen how to convert PowerPoint into images easily using the Syncfusion .NET PowerPoint Library. Take a moment to peruse the documentation, where you’ll find other options and features, all with accompanying code examples.

Apart from this PowerPoint-to-image conversion functionality, our .NET PowerPoint Library has the following significant functionalities and many more:

Are you already a Syncfusion user? You can download the product setup here. If you’re not a Syncfusion user, you can download a free 30-day trial.

If you have questions, contact us through our support forumsupport portal, or feedback portal. We are happy to assist you!

Related blogs

Meet the Author

Dharanya Sakthivel