Knowledgebase (2300)
How to Integrate Spire.Presentation for C++ in a C++ Application
2023-02-16 02:12:44 Written by KoohjiSpire.Presentation for C++ is a professional PowerPoint library built for developers to read, create, edit, and convert PowerPoint documents in any type of C++ applications. This article demonstrates how to integrate Spire.Presentation for C++ into your C++ application in two different ways.
- Install Spire.Presentation for C++ via NuGet
- Install Spire.Presentation for C++ by Manually Importing Libraries
Install Spire.Presentation for C++ via NuGet
Step 1
Create a C++ project in Visual Studio 2022.

Step 2
Right-click "References" in the Solution Explorer and choose "Manage NuGet Package" in the popup menu.

Click "Browse", search for "spire.presentation.cpp", and install it in your project.

Step 3
Right-click "Source Files" in the Solution Explorer, choose "Add" and then "New Item".

Create a .cpp file.

Step 4
Click the .cpp file you just created to write code. Before starting, you need to include the header file “Spire.Presentation.o.h” by adding the following line of code to your program.
- C++
#include "Spire.Presentation.o.h"
The code example below shows you how to create a simple Presentation file using Spire.Presentation for C++.

Install Spire.Presentation for C++ by Manually Importing Libraries
Step 1
Download Spire.Presentation for C++ package and unzip it somewhere on your disc to get the following files.

Step 2
Create a C++ project in Visual Studio 2022.

Step 3
Copy the "include" folder and the "lib" folder from the product package to your project, and save them under the same folder where the .sln file exists.

Step 4
Right-click the project name and select "Properties".

Configure output directory. Depending on the build mode (Debug or Release) you choose, you can set the output directory to "..\lib\x64\debug" or "..\lib\x64\release".

Step 5
Right-click "Source Files" in the Solution Explorer, choose "Add" and then "New Item".

Create a .cpp file.

Step 6
Click the .cpp file you just created to write code. Before starting, you need to include the following two lines of code to your program.
- C++
#include "../include/Spire.Presentation.o.h" #pragma comment(lib,"../lib/x64/debug/Spire.Presentation.Cpp.lib")
The code example below shows you how to create a simple PowerPoint file using Spire.Presentation for C++.

Excel is a wonderful tool for the creation and management of spreadsheets. However, when it comes to sharing these files with others, Excel may not deliver the best results. As soon as you have finalized your report, you can convert it to PDF, which keeps the formatting of your spreadsheets and allows them to be displayed perfectly on a variety of devices. Furthermore, PDFs are secure and can be encrypted to prevent unauthorized changes to the content.
In this article, you will learn how to convert an Excel workbook to PDF and how to convert an Excel worksheet to PDF in C++ using Spire.XLS for C++.
Install Spire.XLS for C++
There are two ways to integrate Spire.XLS for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.XLS for C++ in a C++ Application
Convert an Excel Workbook to a PDF Document in C++
Spire.XLS for C++ offers the Workbook->SaveToFile(LPCWSTR_S fileName, FileFormat fileFormat) method, enabling users to convert an entire workbook to another format file, like PDF, HTML, CSV and XPS. Besides, it offers the ConverterSetting class to specify the convert options, such as whether to automatically adjust the height and width of the cells during conversion. The following are the steps to convert an Excel workbook to PDF using it.
- Create a Workbook object.
- Load a sample Excel document using Workbook->LoadFromFile() method.
- Make worksheets to fit to page when converting using Workbook->GetConverterSetting()->SetSheetFitToPage() method.
- Convert the workbook to PDF using Workbook->SaveToFile() method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
using namespace std;
int main() {
//Specify input file path
wstring inputFilePath = L"C:\\Users\\Administrator\\Desktop\\sample.xlsx";
//Specify output file path and name
wstring outputPath = L"Output\\";
wstring outputFile = outputPath + L"ToPDF.pdf";
//Create a Workbook object
Workbook* workbook = new Workbook();
//Load the source Excel file
workbook->LoadFromFile(inputFilePath.c_str());
//Set worksheets to fit to page when converting
workbook->GetConverterSetting()->SetSheetFitToPage(true);
//Save to PDF
workbook->SaveToFile(outputFile.c_str(), FileFormat::PDF);
workbook->Dispose();
}

Convert a Specific Worksheet to a PDF Document in C++
To export a specific worksheet as a PDF, you must first use the Workbook->GetWorksheets()->Get(index) method to obtain the worksheet, and then use the Worksheet->SaveToPdf(LPCWSTR_S fileName) method to save it. The following are the detailed steps.
- Create a Workbook object.
- Load a sample Excel document using Workbook->LoadFromFile() method.
- Make worksheets to fit to page when converting using Workbook->GetConverterSetting()->SetSheetFitToPage() method.
- Get a specific worksheet using Workbook->GetWorksheets()->Get() method.
- Convert the worksheet to PDF using Worksheet->SaveToPdf() method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
using namespace std;
int main() {
//Specify input file path
wstring inputFilePath = L"C:\\Users\\Administrator\\Desktop\\sample.xlsx";
//Specify output file path and name
wstring outputPath = L"Output\\";
wstring outputFile = outputPath + L"ToPDF.pdf";
//Create a Workbook object
Workbook* workbook = new Workbook();
//Load the source Excel file
workbook->LoadFromFile(inputFilePath.c_str());
//Set worksheets to fit to page when converting
workbook->GetConverterSetting()->SetSheetFitToPage(true);
//Get a specific worksheet
Worksheet* sheet = workbook->GetWorksheets()->Get(0);
//Save it to PDF
sheet->SaveToPdf(outputFile.c_str());
workbook->Dispose();
}

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.
Spire.Email for .NET is a professional .NET Email library specially designed for developers to create, read and manipulate emails from any .NET (C#, VB.NET, ASP.NET, .Net Core, .Net Standard, .NET 5.0, MonoAndroid, Xamarin iOS) platform with fast and high quality performance.
As an independent .NET Email API, Spire.Email for .NET doesn't need Microsoft outlook to be installed on the machine. However, it can incorporate Microsoft Outlook document creation capabilities into any developers' .NET applications.


