Convert only tables from PDF to Excel in C# and VB .Net.
Complete code.
using System;
using System.IO;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
string pathToPdf = @"..\..\Table.pdf";
string pathToExcel = Path.ChangeExtension(pathToPdf, ".xls");
// Convert only tables from PDF to XLS spreadsheet and skip all textual data.
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
// This property is necessary only for registered version
//f.Serial = "XXXXXXXXXXX";
// '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;
// The information includes the names for the culture, the writing system,
// the calendar used, the sort order of strings, and formatting for dates and numbers.
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
ci.NumberFormat.NumberDecimalSeparator = ",";
ci.NumberFormat.NumberGroupSeparator = ".";
f.ExcelOptions.CultureInfo = ci;
f.OpenPdf(pathToPdf);
if (f.PageCount > 0)
{
int result = f.ToExcel(pathToExcel);
// Open the resulted Excel workbook.
if (result==0)
{
System.Diagnostics.Process.Start(pathToExcel);
}
}
}
}
}
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft
Module Sample
Sub Main()
Dim pathToPdf As String = "..\Table.pdf"
Dim pathToExcel As String = Path.ChangeExtension(pathToPdf, ".xls")
' Convert only tables from PDF to XLS spreadsheet and skip all textual data.
Dim f As New SautinSoft.PdfFocus()
' This property is necessary only for registered version
'f.Serial = "XXXXXXXXXXX";
' '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
' The information includes the names for the culture, the writing system,
' the calendar used, the sort order of strings, and formatting for dates and numbers.
Dim ci As New System.Globalization.CultureInfo("en-US")
ci.NumberFormat.NumberDecimalSeparator = ","
ci.NumberFormat.NumberGroupSeparator = "."
f.ExcelOptions.CultureInfo = ci
f.OpenPdf(pathToPdf)
If f.PageCount > 0 Then
Dim result As Integer = f.ToExcel(pathToExcel)
' Open the resulted Excel workbook.
If result = 0 Then
System.Diagnostics.Process.Start(pathToExcel)
End If
End If
End Sub
End Module
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: