Convert PowerPoint to Image in ASP.NET Core Web API
29 Jun 20265 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 Web API.
Steps to convert PowerPoint to Image programmatically
Step 1: Create a new C# ASP.NET Core Web API project.

Step 2: Install the Syncfusion.PresentationRenderer.Net.Core NuGet package as a reference to your project 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: Add a new API controller empty file in the project.

Step 4: Include the following namespaces in the ValuesController.cs file.
using Microsoft.AspNetCore.Mvc;
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;Step 5: Add a new action method ConvertPPTXToImage in ValuesController.cs and include the below code snippet to convert an PowerPoint Presentation to image and download it.
[HttpGet]
[Route("api/PPTXToImage")]
public IActionResult ConvertPPTXToImage()
{
try
{
var fileDownloadName = "Output.jpeg";
const string contentType = "image/jpeg";
var stream = ConvertPresentationToImage();
stream.Position = 0;
return File(stream, contentType, fileDownloadName);
}
catch (Exception ex)
{
// Log or handle the exception
return BadRequest("Error occurred while converting PowerPoint Presentation to Image: " + ex.Message);
}
}Step 6: Implement the ConvertPresentationToImage method in ValuesController.cs.
public static Stream ConvertPresentationToImage()
{
IPresentation pptxDoc = Presentation.Open("Data/Input.pptx");
//Initialize the PresentationRenderer to perform image conversion.
pptxDoc.PresentationRenderer = new PresentationRenderer();
//Convert the first page of the Word document into an image.
Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
//close the word document.
pptxDoc.Close();
//Reset the stream position.
stream.Position = 0;
//Save the image file.
return stream;
}Step 7: Build the project.
Click on Build → Build Solution or press Ctrl+Shift+B to build the project.
Step 8: Run the project.
Click the Start button (green arrow) or press F5 to run the app.
A complete working sample is available on GitHub.
Steps for accessing the Web API using HTTP requests
Step 1: Create a console application.

NOTE
Ensure your ASP.NET Core Web API is running on the specified port before running this client. Adjust the port number if your Web API runs on a different port (check the ASP.NET Core app’s launch settings).
Step 2: Add the below code snippet in the Program.cs file for accessing the Web API using HTTP requests.
This method sends a GET request to the Web API endpoint to retrieve and save the converted Image.
// Create an HttpClient instance
using (HttpClient client = new HttpClient())
{
try
{
// Send a GET request to a URL
HttpResponseMessage response = await client.GetAsync("https://localhost:7260/api/Values/api/PPTXToImage");
// Check if the response is successful
if (response.IsSuccessStatusCode)
{
//Read the content as a string.
Stream responseBody = await response.Content.ReadAsStreamAsync();
FileStream fileStream = File.Create("../../../Output/Output.jpeg");
responseBody.CopyTo(fileStream);
fileStream.Close();
}
else
{
Console.WriteLine("HTTP error status code: " + response.StatusCode);
}
}
catch (HttpRequestException e)
{
Console.WriteLine("Request exception: " + e.Message);
}
}Step 3: Build the project.
Click on Build → Build Solution or press Ctrl+Shift+B to build the project.
Step 4: Run the project.
Click the Start button (green arrow) or press F5 to run the app.
A complete working sample is available on GitHub.
Upon executing the program, the image will be generated as follows.

Looking for the full .NET PowerPoint Library component overview, features, pricing, and documentation? Visit the .NET PowerPoint Library page.
An online sample link to convert PowerPoint Presentation to image in ASP.NET Core.