Convert PowerPoint to PDF in Console application

7 Nov 20234 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 Console application.

Convert PowerPoint to PDF using .NET Core and Latest

The below steps illustrates convert PowerPoint to PDF in console application using .NET Core.

Step 1: Create a new .NET Core console application project.
Create a .NET Core Console application in Visual Studio

Step 2: Install the Syncfusion.PresentationRenderer.Net.Core NuGet package as a reference to your project 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 Program.cs file.

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

Step 4: Include the below code snippet in Program.cs to convert PowerPoint to PDF.

//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))
        {
            //Save the converted PDF.      
            using(FileStream pdfStream = new FileStream("Sample.pdf", FileMode.Create, FileAccess.Write))
            {
                pdfDocument.Save(pdfStream);
            }           
        }
    }
}

You can download a complete working sample from GitHub.

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

Output PDF in .NET Core console application

Convert PowerPoint to PDF in .NET Framework

The below steps illustrates convert PowerPoint to PDF in console application using .NET Framework.

Step 1: Create a new .NET FrameWork console application project.
Create a .NET FrameWork Console application in Visual Studio

Step 2: Install Syncfusion.PresentationToPdfConverter.WinForms NuGet package as a reference to your Windows Forms application from the NuGet.org.

Install Syncfusion.PresentationToPdfConverter.WinForms NuGet package

NOTE

  1. The Syncfusion.PresentationToPdfConverter.WinForms is a dependency for Syncfusion Windows Forms GUI controls and is named with the suffix “WinForms”. It contains platform-independent .NET Framework assemblies (compatible with versions 4.0, 4.5, 4.5.1, and 4.6) for the PowerPoint library and does not include any Windows Forms-related references or code. Therefore, we recommend using this package for .NET Framework Console applications.
  2. 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 Program.cs file.

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

Step 5: Include the below code snippet in Program.cs to convert PowerPoint to PDF.

//Open a PowerPoint Presentation.
using (IPresentation pptxDoc = Presentation.Open("Data/Input.pptx"))
{
    //Convert the PowerPoint Presentation into PDF document.
    using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
    {
        //Save the PDF document.
        pdfDocument.Save("Sample.pdf");
    }
}

You can download a complete working sample from GitHub.

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

Output PDF document in .NET FrameWork console application