C#: Convert PowerPoint to PDF

Converting PowerPoint presentations to PDF offers portability, compatibility, and secure sharing capabilities. By transforming dynamic slides into a static, universally accessible format, users ensure seamless viewing across different devices and platforms.

This article explains how to convert PowerPoint presentations to PDFs using C# and Spire.Presentation for .NET. You'll learn to customize the conversion, including options like including hidden slides, securing PDFs with passwords, and enforcing compliance standards.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Presentation

Convert PowerPoint to PDF in C#

To convert a PowerPoint document to PDF without any customization, you can first load the document using the Presentation.LoadFromFile() method, and then save it as a PDF file using the Presentation.SaveToFile() method.

The steps to convert a PowerPoint document to PDF using C# are as follows:

  • Create a Presentation object.
  • Load a PowerPoint document using Presetation.LoadFromFile() method.
  • Convert it to PDF using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation;

namespace ConvertPowerPointToPdf
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Presentation object
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pptx");

            // Save it to PDF
            presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);

            // Dispose resources
            presentation.Dispose();
        }
    }
}

C#: Convert PowerPoint to PDF

Convert PowerPoint to PDF/A in C#

Spire.Presentation provides the SaveToPdfOption class, which allows you to configure the options for PowerPoint-to-PDF conversion. For instance, you can set the conformance level of the generated PDF document to Pdf/A-1a.

The steps to convert a PowerPoint presentation to a PDF/A document using C# are as follows:

  • Create a Presentation object.
  • Load a PowerPoint document using Presetation.LoadFromFile() method.
  • Get the SaveToPdfOption object using Presentation.SaveToPdfOption property.
  • Set the conformance level to Pdf_A1A using SaveToPdfOption.PdfConformanceLevel property.
  • Convert the presentation to PDF using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation;
using Spire.Presentation.External.Pdf;

namespace ConvertPowerPointToPdfa
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Presentation object
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pptx");

            // Get the SaveToPdfOption object
            SaveToPdfOption options = presentation.SaveToPdfOption;

            // Set the pdf conformance level to pdf_a1a
            options.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1A;

            // Save the presentation to PDF
            presentation.SaveToFile("ToPdfa.pdf",FileFormat.PDF);

            // Dispose resources
            presentation.Dispose();
        }
    }
}

C#: Convert PowerPoint to PDF

Convert PowerPoint to Password-Protected PDF in C#

The SaveToPdfOption class offers the PdfSecurity.Encrypt() method, which enables you to protect the generated PDF document with a password and set document processing permissions, such as allowing printing and filling form fields.

The steps to convert a PowerPoint presentation to a password-protected PDF using C# are as follows.

  • Create a Presentation object.
  • Load a PowerPoint document using Presetation.LoadFromFile() method.
  • Get the SaveToPdfOption object using Presentation.SaveToPdfOption property.
  • Encrypt the generated PDF with a password using SaveToPdfOption.PdfSecurity.Encrypt() method.
  • Convert the presentation to PDF using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation;
using Spire.Presentation.External.Pdf;

namespace ConvertPowerPointToPasswordProtectedPdf
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Presentation object
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pptx");

            // Get the SaveToPdfOption object
            SaveToPdfOption option = presentation.SaveToPdfOption;

            // Encrypt the generated document with a password
            option.PdfSecurity.Encrypt("abc-123",PdfPermissionsFlags.Print | PdfPermissionsFlags.FillFields);

            // Save the presentation to PDF
            presentation.SaveToFile("ToEncryptedPdf.pdf", FileFormat.PDF);

            // Dispose resources
            presentation.Dispose();
        }
    }
}

Convert PowerPoint to PDF with Hidden Slides in C#

When converting a PowerPoint document to PDF, you can include any hidden slides by setting the SaveToPdfOption.ContainHiddenSlides property to true.

The following are the steps to convert PowerPoint to PDF with hidden slides using C#.

  • Create a Presentation object.
  • Load a PowerPoint document using Presetation.LoadFromFile() method.
  • Get the SaveToPdfOption object using Presentation.SaveToPdfOption property.
  • Set the SaveToPdfOption.ContainHiddenSlides property to true to include hidden when converting PowerPoint to PDF.
  • Convert the presentation to PDF using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation;

namespace ConvertPowerPointToPdfWithHiddenSlides
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Presentation object
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pptx");

            // Get the SaveToPdfOption object
            SaveToPdfOption option = presentation.SaveToPdfOption;

            // Enable ContainHiddenSlides option
            option.ContainHiddenSlides = true;

            // Save the presentation to PDF
            presentation.SaveToFile("ToPdfWithHiddenSlides.pdf", FileFormat.PDF);

            // Dispose resources
            presentation.Dispose();
        }
    }
}

Convert PowerPoint to PDF with Custom Slide Size in C#

Customizing the slide size allows you to optimize the PDF for printing on specific paper sizes, like A4, Letter, or even custom sizes. This can be achieved by adjusting the Presentation.SlideSize.Type and Presentation.SlideSize.Size properties.

The steps to convert PowerPoint to PDF with custom slide size are as follows.

  • Create a Presentation object.
  • Load a PowerPoint document using Presetation.LoadFromFile() method.
  • Change the slide size using Presentation.SlideSize.Type and Presentation.SlideSize.Size properties.
  • Auto fit content to the slide by setting Presentation.SlideSizeAutoFit to true.
  • Convert the presentation to PDF using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation;
using System.Drawing;

namespace ConvertPowerPointToPdfWithCustomSlideSize
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Presentation object
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pptx");

            // Set the slide size type as custom
            presentation.SlideSize.Type = SlideSizeType.Custom;

            // Set the custom slide size
            presentation.SlideSize.Size = new SizeF(750, 500);

            // Or, you can set the slide size to a standard slide size like A4
            // presentation.SlideSize.Type = SlideSizeType.A4;

            // Fit content to the new size of slide
            presentation.SlideSizeAutoFit = true;

            // Save the presentation to PDF
            presentation.SaveToFile("ToPdfWithCustomSlideSize.pdf", FileFormat.PDF);

            // Dispose resources
            presentation.Dispose();
        }
    }
}

Convert a Specific Slide in PowerPoint to PDF in C#

To convert a specific slide in a PowerPoint document into a PDF file, you can use the ISlide.SaveToFile() method. Here are the detailed steps.

  • Create a Presentation object.
  • Load a PowerPoint document using Presetation.LoadFromFile() method.
  • Get a specific slide using Presentation.Slides[index] property.
  • Convert it to PDF using ISlide.SaveToFile() method.
  • C#
using Spire.Presentation;

namespace ConvertSpecificSlideToPdf
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Presentation object
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pptx");

            // Get a specific slide
            ISlide slide = presentation.Slides[1];

            // Save it to PDF
            slide.SaveToFile("SlideToPdf.pdf", FileFormat.PDF);

            // Dispose resources
            presentation.Dispose();
        }
    }
}

C#: Convert PowerPoint to PDF

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.