Convert PowerPoint to Image in ASP.NET Core
13 Jun 20243 minutes to read
Syncfusion PowerPoint is a .NET Core PowerPoint library used to create, read, edit and convert PowerPoint presentation programmatically without Microsoft PowerPoint or interop dependencies. Using this library, you can convert a PowerPoint to image in ASP.NET Core.
Steps to convert PowerPoint to Image programmatically
Step 1: Create a new C# ASP.NET Core web application project.
Step 2: Install the Syncfusion.PresentationRenderer.Net.Core NuGet package as reference to your .NET Standard applications from NuGet.org.
NOTE
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to add “Syncfusion.Licensing” assembly reference and include a license key in your projects. Please refer to this link to know about registering Syncfusion license key in your application to use our components.
Step 3: Include the following namespaces in HomeController.cs.
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;
Step 4: A default action method named Index will be present in HomeController.cs. Right click on Index method and select Go To View where you will be directed to its associated view page Index.cshtml.
Step 5: Add a new button in the Index.cshtml as shown below.
@{
Html.BeginForm("ConvertPPTXtoImage", "Home", FormMethod.Get);
{
<div>
<input type="submit" value="Convert PPTX to Image" style="width:200px;height:27px" />
</div>
}
Html.EndForm();
}
Step 6: Add a new action method ConvertPPTXtoImage in HomeController.cs and include the below code snippet to convert a PowerPoint to image in ASP.NET Core.
//Open the file as Stream.
using (FileStream fileStream = new FileStream(Data/Input.pptx", FileMode.Open, FileAccess.Read))
{
//Open the existing PowerPoint presentation.
using (IPresentation pptxDoc = Presentation.Open(fileStream))
{
//Initialize the PresentationRenderer to perform image conversion.
pptxDoc.PresentationRenderer = new PresentationRenderer();
//Convert PowerPoint slide to image as stream.
Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
//Reset the stream position.
stream.Position = 0;
//Download image in the browser.
return File(stream, "application/jpeg", "PPTXtoImage.Jpeg");
}
}
You can download a complete working sample from GitHub.
By executing the program, you will get the image as follows.
Click here to explore the rich set of Syncfusion PowerPoint Library (Presentation) features.
An online sample link to convert PowerPoint Presentation to image in ASP.NET Core.