# Converting PDF Table Content to DataTable using RadSpreadProcessing and UI interaction

## Environment

| Version     | Product                               | Author                                                                          |
| ----------- | ------------------------------------- | ------------------------------------------------------------------------------- |
| 2024.4.1106 | Telerik Document Processing Libraries | [Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova) |

## Description

Learn how to convert a specific table from a PDF file into a [DataTable](https://learn.microsoft.com/en-us/dotnet/api/system.data.datatable?view=net-5.0) object using the **Telerik Document Processing** libraries.

## Solution

The Telerik Document Processing libraries **do not** offer a **direct** method to convert a PDF table to a `DataTable` object. However, a feasible workaround is available. This method uses MS Excel or [RadSpreadsheet](https://docs.telerik.com/devtools/winforms/controls/spreadsheet/overview) for the intermediary conversion step.

1. Select and copy the desired table content from the PDF file.
2. Paste the copied content into **MS Excel** or **RadSpreadsheet**. This step converts the PDF table into an Excel format.
3. Save the document into XLSX with [RadSpreadProcessing](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/overview).
4. Use the RadSpreadProcessing library to convert the Excel document into a `DataTable`. Use the [DataTableFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/data-table/using-data-table-format-provider) from RadSpreadProcessing for this conversion.

Here is a code snippet demonstrating the conversion of an XLSX document to a DataTable using RadSpreadProcessing:

```csharp
using Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx;
using Telerik.Windows.Documents.Spreadsheet.Model;
using System.Data;
using Telerik.Windows.Documents.Spreadsheet.FormatProviders;

// Load the XLSX file
Workbook workbook;
using (FileStream input = new FileStream("path_to_your_xlsx_file.xlsx", FileMode.Open))
{
    IWorkbookFormatProvider formatProvider = new XlsxFormatProvider();
    workbook = formatProvider.Import(input);
}

// Convert the first worksheet to DataTable
Worksheet worksheet = workbook.Worksheets[0];
DataTable dataTable = new DataTable();

DataTableFormatProvider dataTableFormatProvider = new DataTableFormatProvider();
dataTable = dataTableFormatProvider.Export(worksheet);
```

This solution provides a way to parse PDF table content and use it as a `DataTable`, using the features of the Telerik Document Processing libraries.

## See Also

* [RadWordsProcessing Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview)
* [RadSpreadProcessing Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/overview)
* [Using DataTable Format Provider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/data-table/using-data-table-format-provider)
* [Import and Export to Excel File Formats](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xlsx/xlsxformatprovider)
