How to Convert PDF to PowerPoint in .NET with C#

Learn how to use C# to call the PDF to PowerPoint API Tool from pdfRest and quickly turn your PDF formatted documents into PowerPoint files.
Share this page

Why Convert PDF to PowerPoint with C#?

The pdfRest PDF to PowerPoint API Tool provides a simple way to convert PDF documents into PowerPoint presentations. This functionality is particularly useful for professionals who need to repurpose content from reports, brochures, or other PDF documents into a format suitable for presentations. For instance, a business analyst might want to quickly convert a PDF chart into a PowerPoint slide for an upcoming meeting.

By using C# and the pdfRest API, this conversion can be automated, saving time and ensuring consistency across presentations. Read on to learn how.

PDF to PowerPoint with C# Code Example

using System.Text;

using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") })
{
    using (var request = new HttpRequestMessage(HttpMethod.Post, "powerpoint"))
    {
        request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
        request.Headers.Accept.Add(new("application/json"));
        var multipartContent = new MultipartFormDataContent();

        var byteArray = File.ReadAllBytes("/path/to/file");
        var byteAryContent = new ByteArrayContent(byteArray);
        multipartContent.Add(byteAryContent, "file", "file_name");
        byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf");

        request.Content = multipartContent;
        var response = await httpClient.SendAsync(request);

        var apiResult = await response.Content.ReadAsStringAsync();

        Console.WriteLine("API response received.");
        Console.WriteLine(apiResult);
    }
}

Reference: GitHub - pdfRest API Samples

Breaking Down the C# Code

The code block above demonstrates how to make an API call to the pdfRest PDF to PowerPoint endpoint using C#. Let's break it down:

var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") };

This creates an instance of HttpClient and sets the base address for the API calls to the pdfRest API.

var request = new HttpRequestMessage(HttpMethod.Post, "powerpoint");

A new HttpRequestMessage is created for making a POST request to the "powerpoint" endpoint.

request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");

The API key is added to the request headers. Replace "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" with your actual API key provided by pdfRest.

var multipartContent = new MultipartFormDataContent();

A new MultipartFormDataContent is created to hold the file content.

var byteArray = File.ReadAllBytes("/path/to/file");
var byteAryContent = new ByteArrayContent(byteArray);
multipartContent.Add(byteAryContent, "file", "file_name");
byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf");

The PDF file is read into a byte array, wrapped in a ByteArrayContent object, and added to the multipart content. The "file_name" should be replaced with the actual name of your PDF file.

var response = await httpClient.SendAsync(request);

The request is sent asynchronously, and the response is awaited.

var apiResult = await response.Content.ReadAsStringAsync();

The content of the response is read as a string, which contains the result of the conversion.

Beyond the Tutorial

By following the steps above, you've learned how to call the pdfRest PDF to PowerPoint API using C#. This can be a powerful addition to your toolkit, automating the conversion of PDFs to PowerPoint format. You are encouraged to demo all of the pdfRest API Tools in the API Lab and refer to the API Reference documentation for more details.

Note: This is an example of a multipart API call. Code samples using JSON payloads can be found at GitHub - JSON Payload Examples.

Generate a self-service API Key now!

Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.

Compare Plans
Contact Us