Convert PowerPoint Presentations to PDF in C++
Tags: cpp, powerpoint, pdf, convert
Published: 2023-04-27 10:02:37

PDF is a versatile and compatible file format that can be viewed and shared across multiple platforms and devices. By converting PowerPoint presentations to PDF, you can easily share the information in the presentations with anyone, even those who don't have PowerPoint software installed on their devices. This article will illustrate how to programmatically **convert PowerPoint Presentations to PDF in C++**.

- [Convert a PowerPoint Presentation to PDF](#convert-a-powerpoint-presentation-to-pdf-in-c)
- [Convert a PowerPoint Presentation to PDF with Multiple Slides per Page](#convert-a-powerpoint-presentation-to-pdf-with-multiple-slides-per-page-in-c)
- [Convert a PowerPoint Presentation to PDF with a Specific Page Size](#convert-a-powerpoint-presentation-to-pdf-with-a-specific-page-size-in-c) 
- [Convert a Specific PowerPoint Slide to PDF](#convert-a-specific-powerpoint-slide-to-pdf-in-c) 

## Installation
In order to convert PowerPoint presentations to PDF in C++, this article uses [Spire.Presentation for C++](https://www.e-iceblue.com/Introduce/presentation-for-CPP.html) library. 
NuGet is the easiest way to integrate Spire.Presentation for C++ into your application, and there are two ways to install Spire.Presentation for C++ through NuGet.
**1.Install Spire.Presentation for C++ using Manage NuGet Packages.**

- Create or open your project in Visual Studio.
- Click Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution…
- Search for “Spire.Presentation.Cpp” and click install.

**2.Install Spire.Presentation for C++ using Package Manager Console.**

- Create or open your project in Visual Studio.
- Click Tools -> NuGet Package Manager -> Package Manager Console.
- Type the command “Install-Package Spire.Presentation.Cpp” and press enter.

Alternatively, you can also download the package from its [official site](https://www.e-iceblue.com/Download/presentation-for-cpp.html) and then manually import it into your project. For more details, you can check the documentation — [How to Integrate Spire.Presentation for C++ in a C++ Application](https://www.e-iceblue.com/Tutorials/C++/Spire.Presentation-for-C++/Getting-Started/How-to-Integrate-Spire.Presentation-for-C++-in-a-C++-Application.html).

## Convert a PowerPoint Presentation to PDF in C++
To convert a PowerPoint presentation to PDF, you just need to load the presentation and then use the **Presentation->SaveToFile()** method to save it to PDF format. Each slide in the presentation will be converted into a separate PDF page. The detailed steps are as follows:

- Initialize an instance of the **Presentation** class.
- Load a PowerPoint presentation using **Presentation->LoadFromFile()** method.
- Save the presentation to PDF format using **Presentation->SaveToFile()** method.
```cpp
#include "Spire.Presentation.o.h"
using namespace Spire::Presentation;

int main()
{
	//Initialize an instance of the Presentation class
	Presentation* ppt = new Presentation();
	//Load a PowerPoint presentation
	ppt->LoadFromFile(L"Sample.pptx");

	//Save the presentation to PDF format
	ppt->SaveToFile(L"PptToPdf.pdf", FileFormat::PDF);
	delete ppt;
}
```
![Convert PowerPoint Presentations to PDF in C++](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjnd5iwj9ecoah9rcg30.png)
 

## Convert a PowerPoint Presentation to PDF with Multiple Slides per Page in C++
You can use the **Presentation->GetSaveToPdfOption()->SetPageSlideCount()** method to specify the number of slides to be included per PDF page. The detailed steps are as follows:

- Initialize an instance of the **Presentation** class.
- Load a PowerPoint presentation using **Presentation->LoadFromFile()** method.
- Set the number of slides to be included per PDF page using the **Presentation->GetSaveToPdfOption()->SetPageSlideCount()** method.
- Save the presentation to PDF format using **Presentation->SaveToFile()** method.
```cpp
#include "Spire.Presentation.o.h"
using namespace Spire::Presentation;

int main()
{
	//Initialize an instance of the Presentation class
	Presentation* ppt = new Presentation();
	//Load a PowerPoint presentation
	ppt->LoadFromFile(L"Sample.pptx");
	//Specify the number of slides to be included per PDF page
	ppt->GetSaveToPdfOption()->SetPageSlideCount(PageSlideCount::Two);

	//Save the presentation to PDF format
	ppt->SaveToFile(L"PptToPdfWithMultipleSlidesPerPage.pdf", FileFormat::PDF);
	delete ppt;
}
```
![Convert PowerPoint Presentations to PDF with Multiple Slides per PDF Page in C++](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/97zt8h2qouutu4hjl861.png) 

## Convert a PowerPoint Presentation to PDF with a Specific Page Size in C++
You can convert a PowerPoint presentation to PDF with a specific page size by setting the slide size of the presentation to a specific size, then save the presentation to PDF format using the **Presentation->SaveToFile()** method. The detailed steps are as follows:

- Initialize an instance of the **Presentation** class.
- Load a PowerPoint presentation using **Presentation->LoadFromFile()** method.
- Set the slide size type as custom using **Presentation->GetSlidesSize()->SetType()** method.
- Set the slide size to a specific size using **Presentation->GetSlideSize()->SetSize()** method.
- Set slide orientation using **Presentation->GetSlideSize()->SetOrientation()** method.
- Save the presentation to PDF format using **Presentation->SaveToFile()** method.
```cpp
#include "Spire.Presentation.o.h"
using namespace Spire::Presentation;

int main()
{
	//Initialize an instance of the Presentation class
	Presentation* ppt = new Presentation();
	//Load a PowerPoint presentation
	ppt->LoadFromFile(L"Sample.pptx");

	//Set slide size
	ppt->GetSlideSize()->SetType(SlideSizeType::Custom);
	ppt->GetSlideSize()->SetSize(new SizeF(841.68, 595.44)); //The unit of measurement is pt

	//Set slide orientation
	ppt->GetSlideSize()->SetOrientation(SlideOrienation::Landscape);

	//Save the presentation to PDF format
	ppt->SaveToFile(L"PptToPdfWithSpecificPageSize.pdf", FileFormat::PDF);
	delete ppt;
}
```
![Convert PowerPoint Presentations to PDF with a Specific Page Size in C++](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sniy7xpnyltwjiam97n3.png) 

## Convert a Specific PowerPoint Slide to PDF in C++
Sometimes, you may want to convert a specific slide instead of a whole PowerPoint presentation to PDF. In this case, you can use the **ISlide->SaveToFile()** method to save the slide to PDF format. The detailed steps are as follows:

- Initialize an instance of the **Presentation** class.
- Load a PowerPoint presentation using **Presentation->LoadFromFile()** method.
- Access a specific slide using **Presentation->GetSlides()->GetItem()** method.
- Save the slide to PDF format using **ISlide->SaveToFile()** method.
```cpp
#include "Spire.Presentation.o.h"
using namespace Spire::Presentation;

int main()
{
	//Initialize an instance of the Presentation class
	Presentation* ppt = new Presentation();
	//Load a PowerPoint presentation
	ppt->LoadFromFile(L"Sample.pptx");

	//Get the third slide
	ISlide* slide = ppt->GetSlides()->GetItem(2);

	//Save the slide to PDF format
	slide->SaveToFile(L"SlideToPdf.pdf", FileFormat::PDF);
	delete ppt;
}
```
![Convert a Specific PowerPoint Slide to PDF in C++](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6hnceb5q03pzir808vv7.png)