CSV files often contain tabular data where the values are usually separated by comma delimiter. You can convert a CSV file to PDF as well as a PDF file to a CSV file using C# or VB.NET. Aspose APIs offer a lot of file manipulation and conversion features. Let us explore the following headings to learn CSV and PDF conversion:

CSV to PDF and PDF to CSV Converter - API Installation

You need to install Aspose.Cells for .NET as well as Aspose.PDF for .NET API in your environment. You can quickly configure these APIs either by downloading the DLL files from the Downloads section, or you can run the following commands in NuGet Package Manager under the Tools menu in Microsoft Visual Studio IDE.

PM> Install-Package Aspose.Cells
PM> Install-Package Aspose.Pdf

After configuring the APIs successfully, we are all set to perform the inter-conversion of CSV and PDF files.

Convert CSV to PDF File Programmatically using C# or VB.NET

CSV files contain comma-separated values which are usually differentiated by comma. Moreover, each row in a CSV file denotes a tuple or row of data. You can easily convert a CSV file to a PDF document programmatically using C# or VB.NET languages. You can control which symbol do you want to set as a separator character using TxtLoadOptions.Separator property. Likewise, you can also set a string value as a separator delimiter using TxtLoadOptions.SeparatorString property. You need to follow the steps below for converting a CSV file to PDF:

  1. Initialize TxtLoadOptions class object
  2. Specify delimiter using the Separator property
  3. Load input CSV file
  4. Save the output PDF file

The following code snippet is based on these steps which shows how to convert a CSV to PDF Programmatically using C# or VB.NET:

Input CSV File

My Data,,,,,,,

Items A,Items B,Items C,Items D,Items E,Items F,Items G,Items H
12,23,33,66,11,87,99,33
23,22,33,77,31,22,45,56
34,11,12,23,22,34,11,12
45,43,54,88,36,45,45,37
65,65,65,65,13,65,9,35
34,22,27,22,32,23,23,32
213,186,224,341,145,276,232,205

Output PDF File Screenshot

Convert CSV PDF csharp

Convert PDF to CSV File Programmatically using C# or VB.NET

PDF files can contain data in the form of a table. You can convert such PDF file to CSV in your .NET applications. You have already installed Aspose.PDF for .NET API using the NuGet command that we have discussed in the Installation section above. Below are the steps for converting a PDF to CSV file:

  1. Initialize ExcelSaveOptions class object
  2. Set ExcelFormat.CSV format for the output file
  3. Load input PDF file
  4. Save output CSV file

The code below shows how to convert PDF to CSV programmatically using C# or VB.NET:

Conclusion

In this article, we have explored how to convert CSV to PDF and PDF to CSV programmatically using C# or VB.NET in your .NET applications. We have learned how to parse a character or a string delimiter in the CSV files. Moreover, you can reach us out at Free Support Forum for any further help.

See Also