Syncfusion Feedback

Convert an Excel Workbook to PDF with the Syncfusion .NET Excel Library

Overview

The Syncfusion® .NET Excel Library (XlsIO) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can convert an Excel workbook to PDF using C#.

Watch this video to see how to convert an Excel workbook to PDF using the Syncfusion .NET Excel Library:

Watch the video

Steps to convert Excel to PDF

Follow these steps to convert an Excel workbook to PDF using the Syncfusion .NET Excel Library.

Step 1: Create a new project

Start by creating a new C# Console Application project.

Step 2: Install the NuGet package

Add the Syncfusion.XlsIORenderer.Net.Core package to your project from NuGet.org.

Step 3: Include namespaces

Add the following namespaces to your Program.cs file:

using System.IO;
using Syncfusion.XlsIO;
using Syncfusion.XlsIORenderer;
using Syncfusion.Pdf;

Step 4: Add code to convert an Excel workbook to PDF

Use the following code in Program.cs to convert an Excel workbook to PDF.

Run

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
    FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
    IWorkbook workbook = application.Workbooks.Open(inputStream);

    //Initialize XlsIO renderer.
    XlsIORenderer renderer = new XlsIORenderer();

    //Convert Excel document into PDF document .
    PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);

    #region Save
    //Save the workbook.
    FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/WorkbookToPDF.pdf"), FileMode.Create, FileAccess.Write);
    pdfDocument.Save(outputStream);
    #endregion

    //Dispose streams.
    outputStream.Dispose();
    inputStream.Dispose();
}

Get started quickly by downloading the installer and checking license information on the Downloads page.

Syncfusion .NET Excel Library resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.