Spire.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

Step 1

Create a C++ project in Visual Studio 2022.

How to Integrate Spire.Presentation for C++ in a C++ Application

Step 2

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

How to Integrate Spire.Presentation for C++ in a C++ Application

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

How to Integrate Spire.Presentation for C++ in a C++ Application

Step 3

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

How to Integrate Spire.Presentation for C++ in a C++ Application

Create a .cpp file.

How to Integrate Spire.Presentation for C++ in a C++ Application

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++.

How to Integrate Spire.Presentation for C++ in a C++ Application

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.

How to Integrate Spire.Presentation for C++ in a C++ Application

Step 2

Create a C++ project in Visual Studio 2022.

How to Integrate Spire.Presentation for C++ in a C++ Application

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.

How to Integrate Spire.Presentation for C++ in a C++ Application

Step 4

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

How to Integrate Spire.Presentation for C++ in a C++ Application

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".

How to Integrate Spire.Presentation for C++ in a C++ Application

Step 5

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

How to Integrate Spire.Presentation for C++ in a C++ Application

Create a .cpp file.

How to Integrate Spire.Presentation for C++ in a C++ Application

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++.

How to Integrate Spire.Presentation for C++ in a C++ Application

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();
}

C++: Convert Excel Workbooks or Worksheets to PDF

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();
}

C++: Convert Excel Workbooks or Worksheets 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.

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.


page 90

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details