Modify document with C#, VB.NET, ASP.NET from Sautin Software company
google+ facebook twitter youtube    

 

 

How to convert PDF to Excel programmatically in C#

If you are looking for a good solution for converting PDF files to a Excel programmatically, try our PDF Focus .Net.
back to PDF Focus .Net

 

1. Convert PDF file to Excel in C# and .Net:

					        public static void PdfToExcelAsFiles()
        {
            string pdfFile = @"d:\Table.pdf";
            string excelFile = Path.ChangeExtension(pdfFile, ".xls");

            PdfFocus f = new PdfFocus();
            // 'true' = Convert all data to spreadsheet (tabular and even textual).
            // 'false' = Skip textual data and convert only tabular (tables) data.
            f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = false;

            // 'true'  = Preserve original page layout.
            // 'false' = Place tables before text.
            f.ExcelOptions.PreservePageLayout = true;

            f.OpenPdf(pdfFile);

            if (f.PageCount > 0)
            {
                f.ToExcel(excelFile);
            }
        }

				

2. Convert PDF to Excel in memory using MemoryStream in C#:

					        public static void PdfToExcelAsMemoryStream()
        {
            string pdfFile = @"d:\Table.pdf";

            PdfFocus f = new PdfFocus();

            using (FileStream pdfStream = new FileStream(pdfFile, FileMode.Open))
            {
                f.OpenPdf(pdfStream);
                // 'true' = Convert all data to spreadsheet (tabular and even textual).
                // 'false' = Skip textual data and convert only tabular (tables) data.
                f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;

                // 'true'  = Preserve original page layout.
                // 'false' = Place tables before text.
                f.ExcelOptions.PreservePageLayout = true;

                if (f.PageCount > 0)
                {
                    using (MemoryStream excelStream = new MemoryStream(f.ToExcel()))
                    {
                        // Here we have the .xls result as MemoryStream.
                    }
                }
            }
        }

				

3. Convert PDF to Excel in memory as byte[] using C#:

					        public static void PdfToExcelAsByteArray()
        {
            string pdfFile = @"d:\Table.pdf";
            byte[] pdfBytes = File.ReadAllBytes(pdfFile);
            byte[] excelBytes = null;

            PdfFocus f = new PdfFocus();

            f.OpenPdf(pdfBytes);
            // 'true' = Convert all data to spreadsheet (tabular and even textual).
            // 'false' = Skip textual data and convert only tabular (tables) data.
            f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;

            // 'true'  = Preserve original page layout.
            // 'false' = Place tables before text.
            f.ExcelOptions.PreservePageLayout = true;

            if (f.PageCount > 0)
            {
                excelBytes = f.ToExcel();
            }
        }
				

PDF Focus - Top Questions

 

 

components for devolopers
HOME
Since 2002, Sautin Software has been developing and marketing .Net libraries that make it simple to process PDF, HTML and RTF files
I  Validator
Copyright © 2002 - 2017 Sautin Software. All rights reserved support@sautin.com