How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Excel Conversion Library
How to convert Office Excel to PDF file in C#.net web, windows application. No Office, Interop. Free source code included.


Online C#.NET Tutorial for Converting MS Office .xls, .xlsx file to Adobe PDF files Using .NET XDoc.PDF Library. Free online Download.





In this C# tutorial, you learn how to convert, export Microsoft Excel to PDF files in C# class.

  • Convert Excel (.xlsx) to PDF file
  • No need install Microsoft Office or interop
  • Convert multiple Excel to PDF files
  • Combine Excel documents and export to PDF file

How to convert Excel to PDF file without Interop, Office using C#

  1. Download XDoc.PDF Excel Converter C# library
  2. Install C# library to convert Microsoft Excel to PDF file
  3. Step by Step Tutorial


























  • Best Microsoft Office Excel to adobe PDF file converter SDK for Visual Studio .NET
  • An excellent .NET control support convert PDF to multiple Excel formats in C#.NET, includes xls, xlsx, etc
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Turn all Excel spreadsheet into high quality PDF without losing formatting
  • More about PDF conversion: pdf first page to image c#, c# convert png to pdf, c# convert pdf to word programmatically free, word to pdf c#, convert pdf to tiff using c#, convert pdf to bmp c#, convert csv to pdf c# .net.
  • Evaluation library and components for PDF creation from Excel in C#.NET framework
  • Create fillable and editable PDF documents from Excel in both .NET WinForms and ASP.NET
  • Automatically transform, print Excel sheet embeded tables, hyperlinks (url link) to PDF document
  • Convert to PDF with embedded fonts or without original fonts fast
  • Professional .NET PDF converter control for batch conversion
  • Merge all Excel sheets to one PDF file
  • Export PDF from Excel with cell border or no border
  • Free online Excel to PDF converter without email
  • Quick integrate online C# source code into .NET class




C#: Convert Microsoft Excel to Adobe PDF document in Visual C# .NET Project


This is a C# class example for Excel (.xlsx/.xlsm/.xltx) to PDF conversion.



        #region excel(2007 or higher) to pdf (file to file)
        internal static void xlsxToPdf()
        {
            String inputPath = @"C:\demo.xlsx";
            String outputPath = @"C:\output.pdf";
            //convert .docx to .pdf
            XLSXDocument doc = new XLSXDocument(inputPath);
            doc.ConvertToDocument(DocumentType.PDF, outputPath);
        }
        #endregion

        #region excel(2003) to pdf (file to file)
        internal static void xlsToPdf()
        {
            String inputPath = @"C:\demo.xls";
            String outputPath = @"C:\output.pdf";
            //convert .xls to .pdf
            XLSDocument doc = new XLSDocument(inputPath);
            doc.ConvertToDocument(DocumentType.PDF, outputPath);
        }
        #endregion

        #region excel(2007 or higher) to pdf (stream to stream)
        internal static void xlsxStreamToPdf()
        {
            String inputPath = @"";
            byte[] arr = File.ReadAllBytes(inputPath);
            Stream inputStream = new MemoryStream(arr);
            XLSXDocument doc = new XLSXDocument(inputStream);
            Stream outputStream = new MemoryStream();
            doc.ConvertToDocument(DocumentType.PDF, outputStream);
        }
        #endregion

        #region excel(2003) to pdf (stream to stream)
        internal static void xlsStreamToPdf()
        {
            String inputPath = @"";
            byte[] arr = File.ReadAllBytes(inputPath);
            Stream inputStream = new MemoryStream(arr);
            XLSDocument doc = new XLSDocument(inputStream);
            Stream outputStream = new MemoryStream();
            doc.ConvertToDocument(DocumentType.PDF, outputStream);
        }
        #endregion




C# convert two or multiple Excel documents to PDF files (batch conversion)


        #region excel(2007 or higher) to pdf (batch files and single tread)
        internal static void xlsxFilesToPdf()
        {
            String inputDirectory = @"C:\input\";
            String outputDirectory = @"C:\output\";
            String[] files = Directory.GetFiles(inputDirectory, "*.xlsx");
            foreach (String filePath in files)
            {
                int startIdx = filePath.LastIndexOf("\\");
                int endIdx = filePath.LastIndexOf(".");
                String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
                XLSXDocument doc = new XLSXDocument(filePath);
                doc.ConvertToDocument(DocumentType.PDF, outputDirectory + docName + ".pdf");
            }
        }
        #endregion

        #region excel(2003) to pdf (batch files and single tread)
        internal static void xlsFilesToPdf()
        {
            String inputDirectory = @"C:\input\";
            String outputDirectory = @"C:\output\";
            String[] files = Directory.GetFiles(inputDirectory, "*.xls");
            foreach (String filePath in files)
            {
                int startIdx = filePath.LastIndexOf("\\");
                int endIdx = filePath.LastIndexOf(".");
                String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
                XLSDocument doc = new XLSDocument(filePath);
                doc.ConvertToDocument(DocumentType.PDF, outputDirectory + docName + ".pdf");
            }
        }
        #endregion

        #region excel to pdf (batch file and multiple threads)
        internal static void xlsxfiles2pdf()
        {
            String inputDirectory = @"C:\input\";
            String outputDirectory = @"C:\output\";
            String[] files = Directory.GetFiles(inputDirectory, "*.xlsx");
            List<ConversionArgs> args = new List<ConversionArgs>();
            foreach (String filePath in files)
            {
                int startIdx = filePath.LastIndexOf("\\");
                int endIdx = filePath.LastIndexOf(".");
                String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
                ConversionArgs arg = new ConversionArgs(filePath, outputDirectory + docName + ".pdf");
                args.Add(arg);
            }

            List<Thread> threads = new List<Thread>();
            foreach (ConversionArgs arg in args)
            {
                Thread thread = new Thread(xlsxToPdfThread);
                thread.Start(arg);
            }
            foreach (Thread thread in threads)
            {
                thread.Join();
            }
        }

        private static void xlsxToPdfThread(object args)
        {
            ConversionArgs toPdfArgs = (ConversionArgs)args;
            XLSXDocument srcDoc = new XLSXDocument(toPdfArgs.SrcPath);
            if (srcDoc != null)
            {
                srcDoc.ConvertToDocument(DocumentType.PDF, toPdfArgs.DstPath);
                srcDoc.Dispose();
            }
        }
        #endregion




C# combine multiple excel files, and convert to PDF


        #region combine and convert excel(2007 or higher) to single pdf
        internal static void combineAndConvertExcelToPdf()
        {
            String[] files = new String[] { @"C:\demo1.xlsx", @"C:\demo2.xlsx", @"C:\demo3.xlsx" };
            String outputFilePath = @"C:\output.pdf";
            List<MemoryStream> streams = new List<MemoryStream>();
            foreach (String file in files)
            {
                MemoryStream outputStream = new MemoryStream();
                XLSXDocument doc = new XLSXDocument(file);
                doc.ConvertToDocument(DocumentType.PDF, outputStream);
                streams.Add(outputStream);
            }
            PDFDocument.CombineDocument(streams.ToArray(), outputFilePath);
        }
        #endregion

        #region combine and convert excel(2003) to single pdf
        internal static void combineAndConvertExcel03ToPdf()
        {
            String[] files = new String[] { @"C:\demo1.xls", @"C:\demo2.xls", @"C:\demo3.xls" };
            String outputFilePath = @"C:\output.pdf";
            List<MemoryStream> streams = new List<MemoryStream>();
            foreach (String file in files)
            {
                MemoryStream outputStream = new MemoryStream();
                XLSDocument doc = new XLSDocument(file);
                doc.ConvertToDocument(DocumentType.PDF, outputStream);
                streams.Add(outputStream);
            }
            PDFDocument.CombineDocument(streams.ToArray(), outputFilePath);
        }
        #endregion




C# insert excel sheets into pdf document, and create a new PDF file


        #region insert excel(2007 or higher) to pdf
        internal static void insertExcelToPdf()
        {
            String filePath = @"C:\demo.xlsx";
            XLSXDocument doc = new XLSXDocument(filePath);
            MemoryStream stream = new MemoryStream();
            doc.ConvertToDocument(DocumentType.PDF, stream);
            PDFDocument pdf = new PDFDocument(stream);
            int pageCount = pdf.GetPageCount();
            List<BasePage> pages = new List<BasePage>();
            for (int i = 0; i < pageCount; i++)
            {
                pages.Add(pdf.GetPage(i));
            }
            String outputPdf = @"C:\output.pdf";
            PDFDocument desDoc = new PDFDocument(outputPdf);
            int insertLocation = 2;
            desDoc.InsertPages(pages.ToArray(), insertLocation);
            desDoc.Save(@"C:\desDocumcnet.pdf");
        }
        #endregion

        #region insert excel(2003) to pdf
        internal static void insertExcel03ToPdf()
        {
            String filePath = @"C:\demo.xls";
            XLSDocument doc = new XLSDocument(filePath);
            MemoryStream stream = new MemoryStream();
            doc.ConvertToDocument(DocumentType.PDF, stream);
            PDFDocument pdf = new PDFDocument(stream);
            int pageCount = pdf.GetPageCount();
            List<BasePage> pages = new List<BasePage>();
            for (int i = 0; i < pageCount; i++)
            {
                pages.Add(pdf.GetPage(i));
            }
            String outputPdf = @"C:\output.pdf";
            PDFDocument desDoc = new PDFDocument(outputPdf);
            int insertLocation = 2;
            desDoc.InsertPages(pages.ToArray(), insertLocation);
            desDoc.Save(@"C:\desDocumcnet.pdf");
        }
        #endregion