How to convert Excel files to PDF inside .NET?


Our developer’s group have got interesting query from a customer. They have to create an online converter of excel files to PDF on the corporate website!

The problem was this: client’s company keeps on its server statistics reports in xls/xlsx, which had to be displayed on browser by customer’s request. User which sees report must have no possibility of making any changes and editing. Therefore they decided to export Excel files into PDF format, since most modern browsers have the ability to display it. To solve the exporting problem, we offered to our client «Excel to PDF .Net» component which can convert at server side. The component has satisfied customer requirements: to be independent of MS Office Automation and works at Medium trust level.

Our developer’s group has prepared this code to the customer:


         SautinSoft.ExcelToPdf x = new SautinSoft.ExcelToPdf();
        byte[] excelBytes = … //get Excel byte stream here
        byte[] pdfBytes = null;
        int i = x.ConvertBytes(excelBytes, ref pdfBytes);
        //show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            Response.AppendHeader("content-disposition", "attachment; filename=Result.pdf");
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
                    

By clicking the button «Print to PDF», server gets a query to convert corresponding xls/xlsx file. Next the component makes conversion to PDF at server side and returns PDF document to client’s browser. Browser displays this PDF to user or offer to save it on HDD.


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.