Covert Excel To PDF In C#

In this article, I will explain that can we convert excel files to PDF. The easiest way is to use the 3rd party plugin. Here I’m using the SyncFusion library to convert an Excel file to a PDF file. So let’s start it.

Add the Syncfusion.ExcelToPdfConverter.WinForms NuGet package to your project.

Code:

using Syncfusion.ExcelToPdfConverter;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.XlsIO;
using System.Drawing;
using System.IO;

namespace ExcelToPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ExcelEngine excelEngine = new ExcelEngine();

                IApplication app = excelEngine.Excel;
                app.DefaultVersion = ExcelVersion.Xlsx;

                IWorkbook WB = app.Workbooks.Open("C:/Users/VISION-55/Downloads/Review_1580.xlsx");
                IWorksheet worksheet = WB.Worksheets[0];

                ExcelToPdfConverter converter = new ExcelToPdfConverter(worksheet);

                PdfDocument pdfDoc = new PdfDocument();

                pdfDoc = converter.Convert();

                pdfDoc.Save("C:/Users/VISION-55/Downloads/Output.pdf");
                System.Diagnostics.Process.Start("C:/Users/VISION-55/Downloads/Output.pdf");
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
    }
}

Output:

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories