Convert PowerPoint to PDF in ASP.NET Core

2 Dec 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 PDF in ASP.NET Core.

Steps to convert PowerPoint to PDF programmatically

Step 1: Create a new C# ASP.NET Core web application project.

Create ASP.NET Core Web project for PowerPoint file

Step 2: Install the Syncfusion.PresentationRenderer.Net.Core NuGet package as reference to your .NET Standard applications from NuGet.org.

Install Syncfusion.PresentationRenderer.Net.Core Nuget Package

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;
using Syncfusion.Pdf;

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("ConvertPPTXtoPDF", "Home", FormMethod.Get);
    {
        <div>
            <input type="submit" value="Convert PPTX to PDF" style="width:200px;height:27px" />
        </div>
    }
    Html.EndForm();
}

Step 6: Add a new action method ConvertPPTXtoPDF in HomeController.cs and include the below code snippet to convert a PowerPoint to PDF in ASP.NET Core.

//Open the file as Stream
using (FileStream fileStream = new FileStream(Path.GetFullPath("Data/Input.pptx"), FileMode.Open, FileAccess.Read))
{
    //Open the existing PowerPoint presentation with loaded stream.
    using (IPresentation pptxDoc = Presentation.Open(fileStream))
    {
        //Convert the PowerPoint presentation to PDF document.
        using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
        {
            //Create the MemoryStream to save the converted PDF.      
            MemoryStream pdfStream = new MemoryStream();
            //Save the converted PDF document to MemoryStream.
            pdfDocument.Save(pdfStream);
            pdfStream.Position = 0;
            //Download PDF document in the browser.
            return File(pdfStream, "application/pdf", "Sample.pdf");
        }
    }
}

You can download a complete working sample from GitHub.

By executing the program, you will get the PDF document as follows.

Converted PDF from PowerPoint in ASP.NET Core

Click here to explore the rich set of Syncfusion® PowerPoint Library (Presentation) features.

An online sample link to convert PowerPoint Presentation to PDF in ASP.NET Core.