How to Convert CSV to PDF in C++

If you want to write a CSV file to PDF converter in C++, this quick tutorial will provide you with detailed steps and a runnable C++ sample code. You will load the source CSV file to a Workbook class object and then save it as a PDF. Before you convert CSV to PDF in C++, you can also set a number of properties of the output PDF file like writing the entire content of the CSV file to a single page in the output PDF.

Steps to Convert CSV to PDF in C++

  1. Add Aspose.Cells.Cpp to your project by using NuGet Package Manager
  2. Load the sample CSV file into a Workbook class object that is to be converted to PDF in C++
  3. Create IPdfSaveOptions class object to set properties of the output PDF
  4. Configure the output PDF to print the entire text in the source CSV to a single page
  5. Save the workbook as a PDF using the above-mentioned settings

These steps are quite simple as just loading the CSV file and then creating the IPdfSaveOptions class object for configuring the output PDF as per your requirement. We have provided steps and sample code to demonstrate the writing of all the CSV content to a single-page PDF file. However, there is a large number of other properties in the IPdfSaveOptions class that can be set in the output PDF file while you turn PDF to CSV in C++.

Code to Turn PDF to CSV in C++

This code uses Factory::CreateIWorkbook function to load the source CSV file and Factory::CreateIPdfSaveOptions function to create the IPdfSaveOptions class object for setting the desired property using the SetOnePagePerSheet() function in it. This property will render entire CSV contents in a single PDF page and discard the page size set by default in the PageSetup class.

In this tutorial, we have seen the instructions for how to convert CSV to PDF in C++. If you want to convert CSV to Excel, refer to the article on how to change CSV to Excel in C++.

 English