Convert PowerPoint to PDF in ASP.NET MVC

2 Dec 20243 minutes to read

Syncfusion® PowerPoint is a .NET 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 MVC.

Steps to convert PowerPoint to PDF programmatically

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

Create ASP.NET MVC project

Step 2: Select the MVC template to create the project.

Select MVC template

Step 3: Install the Syncfusion.PresentationToPdfConverter.AspNet.Mvc5 NuGet package as reference to your .NET Standard applications from NuGet.org.

Install Syncfusion.PresentationToPdfConverter.AspNet.Mvc5 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 4: Include the following namespace in that HomeController.cs file.

using Syncfusion.Presentation;
using Syncfusion.PresentationToPdfConverter;
using Syncfusion.Pdf;

Step 5: A default action method named Index will be present in HomeController.cs. Right click on this action method and select Go To View where you will be directed to its associated view page Index.cshtml.

Step 6: Add a new button in the Index.cshtml as shown below.

@{
    Html.BeginForm("ConvertPPTXtoPDF", "Home", FormMethod.Get);
    {
        <br />
        <div>
            <input type="submit" value="Convert PPTX to PDF" style="width:200px;height:27px" />
        </div>
    }
    Html.EndForm();
}

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

//Open the file as Stream
using (FileStream pathStream = new FileStream(Server.MapPath("~/App_Data/Input.pptx"), FileMode.Open, FileAccess.Read))
{
    //Opens a PowerPoint Presentation
    using (IPresentation pptxDoc = Presentation.Open(pathStream))
    {     
        //Converts the PowerPoint Presentation into PDF document
        using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
        {
            //Saves the PDF document to MemoryStream.
            MemoryStream stream = new MemoryStream();
            pdfDocument.Save(stream);
            stream.Position = 0;
            //Download PDF document in the browser.
            return File(stream, "application/pdf", "Sample.pdf");
        }                    
    }
}

You can download a complete working sample from GitHub

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

Converted PDF from PowerPoint in ASP.NET MVC

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 MVC