This basic tutorial guides on how to convert CSV to PDF using C# where the CSV can be a comma-separated or a specified character delimited file. The CSV is considered to be a common and easy mechanism to export and import data and on the other hand, PDF is used for viewing data independent of hardware, software, and operating system. Using this tutorial you will change CSV to PDF using C# with the help of a few lines of code in any of the common operating systems.
Steps to Convert CSV to PDF using C#
- Add Aspose.Cells in your conversion application using the Nuget Package Manager
- Create a TxtLoadOptions class object to set the separator used in the source CSV file
- Initialize Workbook class object to load the CSV file using the settings in the TxtLoadOptions object
- Instantiate the PdfSaveOptions to set parameters for the output PDF file
- Set the type of grid to be displayed in the output PDF file
- Save the PDF file using the PdfSaveOptions class object configured above
These quick steps describe the operation to transfer CSV to PDF using C# such that first, we load the required libraries and then load the sample CSV file that is to be converted to PDF. In the last step, we configure the output PDF file like we set the grid lines to be displayed in the output PDF file.
Code to Change CSV to PDF using C#
In this tutorial to convert CSV to PDF C# language is used where necessary references are added along with the configuration of the project from the NuGet package manager. We have used the TxtLoadOptions object for reading the CSV file which contains a lot of properties like we set the delimiter character however, you can set other properties also like CultureInfo, Encoding, ExtendToNextSheet, and many more. Similarly while saving the PDF file, we have set the grid lines style using the PdfSaveOptions however, you can also set AllColumnsInOnePagePerSheet, CalculateFormula, OnePagePerSheet, PdfCompression, SecurityOptions, etc.
We have seen here the process to convert from CSV to PDF using C# however if you want to learn the CSV to Excel conversion, refer to the article on how to convert CSV to Excel in C#.