Friday, November 28, 2014

How to convert PDF TO EXCEL File using Freeware DLL

Hi,


You may use this .Net assembly to convert PDF to Excel (.xls).


Let us say, you want to convert only tabular data (and skip text) from PDF to Excel in C#:



SautinSoft.PdfFocus f = new PdfFocus();
f.OpenPdf(@"d:\Invoice.pdf");

f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = false;

if (f.PageCount > 0)
f.ToExcel(@"d:\Invoice.xls");



Or if you want to convert textual and tabular data from PDF to Excel, but only on 1st page:



string pathToPdf = @"c:\Table.pdf";
string pathToExcel = Path.ChangeExtension(pathToPdf, ".xls");

// Here we have our PDF and Excel docs as byte arrays
byte[] pdf = File.ReadAllBytes(pathToPdf);
byte[] xls = null;

// Convert PDF document to Excel workbook in memory
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;


f.OpenPdf(pdf);

if (f.PageCount > 0)
{
xls = f.ToExcel(1,1);

//Save Excel workbook to a file in order to show it
if (xls!=null)
{
File.WriteAllBytes(pathToExcel, xls);
System.Diagnostics.Process.Start(pathToExcel);
}
}

I hope this would be helpful for you!


Max



No comments:

Post a Comment