Articles in this section
Category / Section

How to convert a PowerPoint presentation file to metafile image [EMF] in WinForms?

2 mins read

Syncfusion Essential Presentation is a .NET PowerPoint Library used to create, open, read, edit, and export PowerPoint presentations. Using this library, you can export a PowerPoint presentation slides as EMF images in C# and VB.NET. Exporting the PowerPoint slides as EMF images will result good quality images.

Steps to convert a PowerPoint presentation file to metafile images programmatically:

  1. Create a new C# console application.

Creating console application

  1. Install Syncfusion.Presentation.Base NuGet package to the console application project from nuget.org. For more information about adding a NuGet feed in Visual Studio and installing NuGet packages, refer to documentation.

Installing NuGet Packages

  1. Install Syncfusion.OfficeChartToImageConverter.Wpf NuGet package to the console application project from nuget.org. For more information about adding a NuGet feed in Visual Studio and installing NuGet packages, refer to documentation.

NuGet packages

  1. Include the following namespace in the Program.cs file.
    using Syncfusion.Presentation;
    using Syncfusion.OfficeChartToImageConverter;
    

 

Imports Syncfusion.Presentation
Imports Syncfusion.OfficeChartToImageConverter

 

  1. Use the following code snippet to convert the slides in the PowerPoint presentation as .emf images.
    //Open the PowerPoint Presentation.
    IPresentation powerpointDoc = Presentation.Open("Sample.pptx");
     
    //Create an instance of ChartToImageConverter and assign it to ChartToImageConverter property of presentation.
    powerpointDoc.ChartToImageConverter = new ChartToImageConverter();
     
    //Iterate the slides in the PowerPoint file and convert to image
    foreach (ISlide slide in powerpointDoc.Slides)
    {
        //Convert the slide as EMF image stream.
        System.IO.Stream emfImgStream = slide.ConvertToImage(Syncfusion.Drawing.ImageFormat.Emf);
     
        //Create a FileStream object to write the EMF image stream to a file
        using (System.IO.FileStream fileStream = System.IO.File.Create("Slide_" + slide.SlideNumber + ".emf", (int)emfImgStream.Length))
        {
            //Fill the bytes array with the EMF stream data
            byte[] bytesInStream = new byte[emfImgStream.Length];
     
            //Copy the EMF image stream to FileStream
            emfImgStream.Read(bytesInStream, 0, (int)bytesInStream.Length);
     
            //Write the EMF image to the specified file
            fileStream.Write(bytesInStream, 0, bytesInStream.Length);
        }
    }
     
    //Close the Presentation.
    powerpointDoc.Close();
    

 

'Open the PowerPoint Presentation.
Dim powerpointDoc As IPresentation = Presentation.Open("Sample.pptx")
 
'Create an instance of ChartToImageConverter and assign it to ChartToImageConverter property of presentation.
powerpointDoc.ChartToImageConverter = New ChartToImageConverter()
 
'Iterate the slides in the PowerPoint file and convert to image
For Each slide As ISlide In powerpointDoc.Slides
    'Convert the slide as EMF image stream.
    Dim emfImgStream As System.IO.Stream = slide.ConvertToImage(Syncfusion.Drawing.ImageFormat.Emf)
 
    'Create a FileStream object to write the EMF image stream to a file
    Using fileStream As System.IO.FileStream = System.IO.File.Create("Slide_" + slide.SlideNumber + ".emf", CInt(emfImgStream.Length))
        'Fill the bytes array with the EMF stream data
        Dim bytesInStream As Byte() = New Byte(emfImgStream.Length - 1) {}
 
        'Copy the EMF image stream to FileStream
        emfImgStream.Read(bytesInStream, 0, CInt(bytesInStream.Length))
 
        'Write the EMF image to the specified file
        fileStream.Write(bytesInStream, 0, bytesInStream.Length)
    End Using
Next
 
'Close the Presentation.
powerpointDoc.Close()

 

You can download the working sample from Convert-PowerPoint-To-EMF-Images.Zip.

An online sample link to convert a PowerPoint presentation slides as images. Take a moment to peruse the documentation, where you can find mode details about exporting the PowerPoint slides as images with code examples. Refer here to explore the complete set of Syncfusion Essential Presentation features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.


Conclusion

I hope you enjoyed learning about how to convert a PowerPoint presentation file to metafile image [EMF] in WinForms.

You can refer to our WinForms Presentation feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our  WinForms Presentation example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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