PDF format is widely used to exchange documents among the stakeholders. In various cases, the documents are converted to PDF format before they are shared. Thus, PDF is known to be a standard file format in such cases. In this article, we will target Excel to PDF conversion programmatically. Particularly, you will learn how to convert Excel XLSX or XLS workbooks to PDF files using C++.
- C++ Excel to PDF Converter API
- Convert Excel Files to PDF in C++
- Convert Excel to PDF with Compliance Level
- Set PDF Creation Date in Excel to PDF Conversion
- Get Free License
C++ Excel to PDF Converter API
Aspose.Cells for C++ is designed to implement Excel automation features within C++ applications. Using the API, you can create new Excel files from scratch as well as manipulate the existing ones. The API’s built-in spreadsheet converter lets you convert Excel files to other formats with high fidelity. You can either download the API package or install it from NuGet.
Install-Package Aspose.Cells.Cpp
Convert Excel Files to PDF in C++
The following are the steps to convert Excel files to PDF using Aspose.Cells.
- Load the Excel file using intrusive_ptr<Aspose::Cells::IWorkbook> pointer.
- Save the Excel file as a PDF using the Save(StringPtr, SaveFormat_Pdf) method of IWorkbook class.
The following code sample shows how to convert Excel files to PDF using C++.
C++ Excel to PDF with Compliance Level
Aspose.Cells for C++ also allows you to set the compliance level of the converted PDF file such as PDF/A. For this, the API provides an additional class named as IPdfSaveOptions that allows you to customize the Excel to PDF conversion with different options. The following are the steps to convert an Excel file to PDF with PDF/A compliance.
- Load the Excel file using intrusive_ptr<Aspose::Cells::IWorkbook> pointer.
- Use intrusive_ptr<Aspose::Cells::IPdfSaveOptions> pointer to create PDF save options.
- Set compliance level using IPdfSaveOptions->SetCompliance(Aspose::Cells::Rendering::PdfCompliance) method.
- Save the Excel file as PDF using Save(StringPtr, IPdfSaveOptions) method of IWorkbook class.
The following code sample shows how to set compliance level in Excel to PDF conversion.
Set PDF Creation Date in Excel to PDF
You can also set the creation date and time for the converted PDF file. For this, you can simply use IPdfSaveOptions->SetCreatedTime(new Aspose::Cells::Systems::DateTime) method. The following are the steps to perform this operation.
- Load the Excel file using intrusive_ptr<Aspose::Cells::IWorkbook> pointer.
- Use intrusive_ptr<Aspose::Cells::IPdfSaveOptions> pointer to create PDF save options.
- Set date and time using IPdfSaveOptions->SetCreatedTime(new Aspose::Cells::Systems::DateTime(2017, 5, 25)) method.
- Save the Excel file as PDF using Save(StringPtr, IPdfSaveOptions) method of IWorkbook class.
The following code sample shows how to set the creation date and time in Excel to PDF conversion.
Get a Free License
You can get a free temporary license in order to try the API without evaluation limitations.
Conclusion
In this article, you have learned how to convert Excel files to PDF using C++. Furthermore, you have seen how to set the compliance level and the creation date for the converted PDF file. You can explore more about the API using documentation.