Introduction
In this blog, we will explore the process of converting Excel to PDF using Syncfusion Excel (XlsIO) library. This method ensures that all the information contained within your spreadsheet remains uneditable, regardless of who accesses it. You can convert your Excel to PDF and can use the converted file as a permanent record. The Syncfusion Excel (XlsIO) library is a .Net library that is used to create and modify excel files by using C#.
Syncusion
Syncfusion Excel (XlsIO) library is a .Net Excel library used for creating, reading, and editing Excel documents. Excel plays a vital role in our daily lives, serving as a tool for record management, data analysis, calculations, analytical tool for business and visualization. PDF (Portable Document Format) is another file format, similar to Excel, capable of capturing all the elements of a printed document as an electronic image that you can be viewed, navigated, and printed. The Syncfusion Excel (XlsIO) library helps you to convert Excel file to PDF in C# and VB.NET seamlessly.
XlsIO helps to convert Excel to PDF by loading the workbook or worksheet into ExcelToPDFConverter and converts the loaded document using Convert method. This conversion is supported across various platforms like Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, Xamarin and Azure.
Creating Web API for file conversion
Step 1 : Create a new ASP.Net core Web API project.
Step 2 : Install the Syncfusion.XlsIORenderer package through the nuget package manager to convert Excel to pdf.
Step 3 : Import the below mentioned statements in the controller.
- Syncfusion.Pdf
- Syncfusion.XlsIO
- Syncfusion.XlsIORenderer
Step 4 : Create an POST action that received file as a request. The received file is converted to pdf using Syncfusion package and the converted file is returned as a response. Then add the following code snippet to read and convert the uploaded excel file to PDF.
using Microsoft.AspNetCore.Mvc;
using Syncfusion.Pdf;
using Syncfusion.XlsIO;
using Syncfusion.XlsIORenderer;
using static System.Net.Mime.MediaTypeNames;
namespace ExceltoPDFDemo.Controllers
{
[ApiController]
[Route("[controller]")]
public class ExcelToPDFController : ControllerBase
{
[HttpPost]
public IActionResult ConvertExcelToPDF(IFormFile file)
{
MemoryStream stream = new MemoryStream();
file.CopyTo(stream);
stream.Position = 0;
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
using (ExcelEngine excelEngine = new ExcelEngine())
{
PdfDocument pdfDocument = new PdfDocument();
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open(stream);
XlsIORenderer renderer = new XlsIORenderer();
pdfDocument = renderer.ConvertToPDF(workbook);
MemoryStream pdfStream = new MemoryStream();
pdfDocument.Save(pdfStream);
return File(pdfStream.ToArray(), "application/pdf", "ConvertedPDF.pdf");
}
}
}
}
Step 5 : Run the project to convert Excel files into PDF. Select the file that has to be converted into pdf and call the api.


Conclusion
Finally, we have successfully converted an Excel file into a PDF format using Syncfusion library.
No Comment! Be the first one.