Convert PowerPoint to PDF in ASP.NET

16 Oct 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.

NOTE

This ASP.NET Web Form platform is deprecated, you can use the same product from ASP.NET Core platform. For more information on migrating the .NET Word library from .NET Framework to .NET Core, refer here.

Steps to convert PowerPoint to PDF programmatically

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

Create ASP.NET Web project

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

Select Web Forms template

Step 3: 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 4: Include the following namespaces in MainPage.aspx.cs.

using Syncfusion.Pdf;
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;

Step 5: Add a new button in the MainPage.aspx as shown below.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="Convert_PowerPoint_Presentation_to_PDF.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
             <asp:Button ID="Button1" runat="server" Text="Convert PPTX to PDF" OnClick="OnButtonClicked" />
        </div>
    </form>
</body>
</html>

Step 6: Include the below code snippets in the click event of the button in MainPage.aspx.cs, to convert a PowerPoint to PDF in ASP.NET.

string filePath = Server.MapPath("~/App_Data/Input.pptx");
//Open the existing PowerPoint presentation.
using (IPresentation pptxDoc = Presentation.Open(filePath))
{
    //Create the MemoryStream to save the converted PDF.
    using (MemoryStream pdfStream = new MemoryStream())
    {
        //Convert the PowerPoint presentation to PDF document.
        using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
        {
            //Save the converted PDF document to MemoryStream.
            pdfDocument.Save(pdfStream);
            pdfStream.Position = 0;
        }
        //Create the output PDF file stream.
        using (FileStream fileStreamOutput = File.Create(Server.MapPath("~/Sample.pdf")))
        {
            //Copy the converted PDF stream into created output PDF stream.
            pdfStream.CopyTo(fileStreamOutput);
        }
    }
}

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

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.