Convert an Excel document to PDF in Windows Forms
22 Jul 20265 minutes to read
Syncfusion® XlsIO is a .NET Excel Library used to create, read, edit, and convert Excel documents programmatically, without Microsoft Excel or interop dependencies.
Steps to convert an Excel document to PDF in Windows Forms
Step 1: Create a new Windows Forms application project.

Step 2: Name the project, choose the framework, and click Create.

Step 3: Install the Syncfusion.ExcelToPdfConverter.WinForms NuGet package as a reference to your project from NuGet.org. This package transitively pulls in the required Syncfusion.XlsIO.Base and Syncfusion.Pdf.Base assemblies.

NOTE
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or from the NuGet feed, you must also add the
Syncfusion.Licensingreference and register a license key. Refer to this link to learn how to register the Syncfusion® license key. The simplest approach is to add the following call in theMainmethod (or inProgram.csfor .NET 6+ WinForms) before constructing theExcelEngine:Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR_LICENSE_KEY");
Step 4: Add a new button in the Form1.Designer.cs as shown below.
private Button btnCreate;
private Label label;
private void InitializeComponent()
{
label = new Label();
btnCreate = new Button();
//Label
label.Location = new System.Drawing.Point(0, 40);
label.Size = new System.Drawing.Size(426, 35);
label.Text = "Click the button to Convert Exel document to PDF generated by Essential<sup>®</sup> XlsIO. Please note that Microsoft Excel Viewer or Microsoft Excel is required to view the resultant Excel document";
label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//Button
btnCreate.Location = new System.Drawing.Point(180, 110);
btnCreate.Size = new System.Drawing.Size(85, 36);
btnCreate.Text = "Convert Excel document to PDF";
btnCreate.Click += new EventHandler(btnConvert_Click);
//Create Word
ClientSize = new System.Drawing.Size(450, 150);
Controls.Add(label);
Controls.Add(btnCreate);
Text = "Convert Excel document to PDF";
}Step 5: Add the following namespaces in Form1.cs.
using Syncfusion.XlsIO;
using Syncfusion.Pdf;
using Syncfusion.ExcelToPdfConverter;Step 6: Add the following code in the btnConvert_Click handler in Form1.cs to convert an Excel document to PDF. Place a Sample.xlsx file in the project’s bin\Debug folder (or set its Copy to Output Directory property to Copy if newer) so the relative path resolves.
private void btnConvert_Click(object sender, EventArgs e)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
//Open the existing Excel workbook. Adjust the path as required.
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
//Initialize the Excel-to-PDF converter
ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);
//Convert the Excel document to a PDF document
PdfDocument pdfDocument = converter.Convert();
//Save the converted PDF document to the application's working directory
pdfDocument.Save("Sample.pdf");
//Close the workbook and the PDF document to release resources
workbook.Close();
pdfDocument.Close();
//Notify the user that the PDF was generated
MessageBox.Show("Sample.pdf has been saved to " + Application.StartupPath);
}
}NOTE
For additional control over page size, orientation, and font embedding, pass an
ExcelToPdfConverterSettingsinstance when creating theExcelToPdfConverterand call theConvert(ExcelToPdfConverterSettings)overload. See the Excel-to-PDF conversion settings for details.
A complete working example of how to convert an Excel document to PDF in Windows Forms is present on this GitHub page.
By executing the program, you will get the PDF document as shown below.

Click here to explore the rich set of Syncfusion® Excel library (XlsIO) features.
An online sample link to convert an Excel document to PDF in ASP.NET Core.