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 that define rows of data. You can easily convert a CSV file to a PDF document programmatically using C# or VB.NET. Use the TxtLoadOptions.Separator property to set a single character delimiter, or TxtLoadOptions.SeparatorString for a string delimiter. Follow these steps to convert 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 snippet follows these steps and shows how to convert CSV to PDF programmatically using C# or VB.NET:

{{< gist aspose-com-gists e7836763c0ea85cdb50c9cf4f34c40d6 “CSVtoPDF.cs” >}}

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

{{< figure align=center src=“images/Convert-CSV-PDF-Csharp.png” alt=“Convert CSV PDF csharp”>}}

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

PDF files can contain data in table form. You can convert such a PDF file to CSV in your .NET applications. After installing Aspose.PDF for .NET via NuGet as described earlier, use these steps:

  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 demonstrates how to convert PDF to CSV programmatically using C# or VB.NET:

{{< gist aspose-com-gists e7836763c0ea85cdb50c9cf4f34c40d6 “PDFtoCSV.cs” >}}

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