Convert PowerPoint to PDF or PDF to PowerPoint in C# and VB.NET

PDF is known to be the best format for delivering and sharing information, but it is not suitable for presentation purposes. In contrast, PowerPoint is ideal for presenting information, but it may not work well when distributing information because it’s not platform-independent. To a certain extent, PDF and PowerPoint are two complementary formats, that’s why we need to convert between PDF and PowerPoint. This article will teach you how to convert PowerPoint to PDF or PDF to PowerPoint in C# and VB.NET.

In this article, we will illustrate the following topics:

  • Convert PowerPoint to PDF in C# and VB.NET
  • Customize PowerPoint to PDF Conversion in C# and VB.NET
  • Convert a Specific PowerPoint Slide to PDF in C# and VB.NET
  • Convert PDF to PowerPoint in C# and VB.NET

Prerequisites

Step 1 - Create a C#/VB.NET project in Visual Studio

Step 2 - Install the Spire.Office library

There are many libraries to convert PowerPoint and PDF documents, in this article, we’re using Spire.Office library. You can install the library from NuGet using the Package manager console:

PM> Install-Package Spire.Office

Now, you have done the prerequisites. Let’s dive into the code part.

Convert PowerPoint to PDF in C# and VB.NET

The Presentation class in the library is used to work with PowerPoint presentations. To convert a PowerPoint presentation to PDF, you can simply load the presentation and then use the Presentation.SaveToFile(string fileName, FileFormat.PDF) method to save it to PDF format. Each slide in the presentation will be converted into a separate PDF page. The following are the conversion steps:

  • Create an instance of the Presentation class.
  • Load the PowerPoint presentation using Presentation.LoadFromFile(string fileName) method.
  • Save the presentation to PDF format using Presentation.SaveToFile(string fileName, FileFormat.PDF) method.

The following code samples show how to convert a PowerPoint presentation to PDF in C# and VB.NET:

C#

using Spire.Presentation;

namespace ConvertPptToPdf
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            Presentation ppt = new Presentation();
            //Load a PowerPoint presentation
            ppt.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");

            //Save the presentation to PDF format
            ppt.SaveToFile("PptToPdf.pdf", Spire.Presentation.FileFormat.PDF);
            ppt.Dispose();
        }
    }
}

VB.NET

Imports Spire.Presentation

Namespace ConvertPptToPdf
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Initialize an instance of the Presentation class
            Dim ppt As Presentation = New Presentation()
            'Load a PowerPoint presentation
            ppt.LoadFromFile("C:\Users\Administrator\Desktop\Sample.pptx")

            'Save the presentation to PDF format
            ppt.SaveToFile("PptToPdf.pdf", Spire.Presentation.FileFormat.PDF)
            ppt.Dispose()
        End Sub
    End Class
End Namespace

Input PowerPoint Presentation

Converted PDF

Customize PowerPoint to PDF Conversion in C# and VB.NET

The library provides the SaveToPdfOption class that allows you to customize PowerPoint to PDF conversion. You can use the Presentation.SaveToPdfOption property to get the SaveToPdfOption object, then use the following properties the SaveToPdfOption class offers to set conversion options:

  • ContainHiddenSlides: Indicates whether to export hidden slides to PDF.
  • PageSlideCount: Specify the number of slides to be included per PDF page.
  • PdfConformanceLevel: Set the conformance level of the converted PDF, such as Pdf/A-1a, Pdf/A-1b, Pdf/A-2a, Pdf/A-2b, Pdf/A-3a, Pdf/A-3b, or Pdf/X-1a:2001.
  • PdfSecurity: Set the security settings for the converted PDF, such as open password and permission password.

The following code sample shows how to convert a PowerPoint presentation to PDF with a specific conformance level in C# and VB.NET:

C#

using Spire.Pdf;
using Spire.Presentation;

namespace ConvertPptToPdfWithOptions
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            Presentation ppt = new Presentation();
            //Load a PowerPoint presentation
            ppt.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");

            //Get the SaveToPdfOption object
            SaveToPdfOption options = ppt.SaveToPdfOption;
            //Set the conformance level of the converted PDF
            options.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1A;

            //Save the presentation to PDF format
            ppt.SaveToFile("PptToPdfWithAdvancedOption.pdf", Spire.Presentation.FileFormat.PDF);
            ppt.Dispose();
        }
    }
}

VB.NET

Imports Spire.Pdf
Imports Spire.Presentation

Namespace ConvertPptToPdfWithOptions
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Initialize an instance of the Presentation class
            Dim ppt As Presentation = New Presentation()
            'Load a PowerPoint presentation
            ppt.LoadFromFile("C:\Users\Administrator\Desktop\Sample.pptx")

            'Get the SaveToPdfOption object
            Dim options As SaveToPdfOption = ppt.SaveToPdfOption
            'Set the conformance level of the converted PDF
            options.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1A

            'Save the presentation to PDF format
            ppt.SaveToFile("PptToPdfWithAdvancedOption.pdf", Spire.Presentation.FileFormat.PDF)
            ppt.Dispose()
        End Sub
    End Class
End Namespace

Convert a Specific PowerPoint Slide to PDF in C# and VB.NET

To convert a specific slide in a PowerPoint presentation to PDF, you can use the ISlide.SaveToFile(string fileName, FileFormat.PDF) method.

The following are the conversion steps:

  • Create an instance of the Presentation class.
  • Load the PowerPoint presentation using Presentation.LoadFromFile(string fileName) method.
  • Access a specific slide by its index using Presentation.Slides[int] property.
  • Save the slide to PDF using ISlide.SaveToFile(string fileName, FileFormat.PDF) method.

C#

using Spire.Presentation;

namespace ConvertSpecificSlideToPdf
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            Presentation ppt = new Presentation();
            //Load a PowerPoint Presentation
            ppt.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Save the slide to PDF
            slide.SaveToFile("SlideToPdf.pdf", Spire.Presentation.FileFormat.PDF);
            ppt.Dispose();
        }
    }
}

VB.NET

Imports Spire.Presentation

Namespace ConvertSpecificSlideToPdf
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Initialize an instance of the Presentation class
            Dim ppt As Presentation = New Presentation()
            'Load a PowerPoint Presentation
            ppt.LoadFromFile("C:\Users\Administrator\Desktop\Sample.pptx")

            'Get the first slide
            Dim slide As ISlide = ppt.Slides(0)

            'Save the slide to PDF
            slide.SaveToFile("SlideToPdf.pdf", Spire.Presentation.FileFormat.PDF)
            ppt.Dispose()
        End Sub
    End Class
End Namespace

Convert PDF to PowerPoint in C# and VB.NET

The PdfDocument class in the library is used to work with PDF files. To convert a PDF file to PowerPoint, you just need to load the PDF file and then use the PdfDocument.SaveToFile(string fileName, FileFormat.PPTX) method to save it to PowerPoint PPTX format. The following are the conversion steps:

  • Initialize an instance of the PdfDocument class.
  • Load the PDF file using PdfDocument.LoadFromFile(string fileName) method.
  • Save the PDF to PowerPoint PPTX format using PdfDocument.SaveToFile(string fileName, FileFormat.PPTX) method.

C#

using Spire.Pdf;

namespace ConvertPdfToPptx
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            PdfDocument pdf = new PdfDocument();
            //Load a PDF file
            pdf.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pdf");

            //Save the PDF to PPTX document
            pdf.SaveToFile("PdftoPowerPoint.pptx", Spire.Pdf.FileFormat.PPTX);
            pdf.Close();
            pdf.Dispose();
        }
    }
}

VB.NET

Imports Spire.Pdf

Namespace ConvertPdfToPptx
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Initialize an instance of the Presentation class
            Dim pdf As PdfDocument = New PdfDocument()
            'Load a PDF file
            pdf.LoadFromFile("C:\Users\Administrator\Desktop\Sample.pdf")

            'Save the PDF to PPTX document
            pdf.SaveToFile("PdftoPowerPoint.pptx", Spire.Pdf.FileFormat.PPTX)
            pdf.Close()
            pdf.Dispose()
        End Sub
    End Class
End Namespace

Input PDF

Converted PowerPoint presentation