How to Convert CSV Document to PDF using C#, VB.NET?
Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Using this library, you can convert CSV document to PDF using Excel to PDF conversion feature in
This article explains how to convert CSV document to PDF using
Include the following namespace in the Program.cs file.
C#
using Syncfusion.XlsIO;
using Syncfusion.XlsIORenderer;
using Syncfusion.Pdf;
VB.NET
Imports Syncfusion.XlsIO
Imports Syncfusion.ExcelToPdfConverter
Imports Syncfusion.Pdf
Use the following code snippet for converting CSV document to PDF.
C#
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("Data/Sample.csv", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorksheet sheet = workbook.Worksheets[0];
//Auto-fit all columns in the used range to prevent cropping
sheet.UsedRange.AutofitColumns();
//Initialize XlsIORenderer
XlsIORenderer renderer = new XlsIORenderer();
//Convert CSV document to PDF document
PdfDocument pdfDocument = renderer.ConvertToPDF(sheet);
//Saving the PDF document
FileStream outputStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite);
pdfDocument.Save(outputStream);
//Dispose streams
inputStream.Dispose();
outputStream.Dispose();
}
VB.NET
Using excelEngine As New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Open("Sample.csv")
Dim sheet As IWorksheet = workbook.Worksheets(0)
'Auto-fit all columns in the used range to prevent cropping
sheet.UsedRange.AutofitColumns()
'Initialize the ExcelToPdfConverter
Dim converter As New ExcelToPdfConverter(workbook)
'Convert CSV document to PDF document
Dim document As PdfDocument = converter.Convert()
'Saving the PDF document
document.Save("Output.pdf")
End Using
You can get the complete sample for converting CSV document to PDF from here.
I hope you enjoyed learning about how to convert CSV document to PDF using
You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.
If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion components.
If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!
Take a moment to peruse the documentation where you can find basic Excel document processing options along with the features like import and export data, chart, formulas, conditional formatting, data validation, tables, pivot tables and, protect the Excel documents, and most importantly, the PDF, CSV and Image conversions with code examples.