---
title: "Extract table from PDF in C#: Read and parse PDF table | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/extraction/tables/"
md_url: "https://www.nutrient.io/guides/dotnet/extraction/tables.md"
last_updated: "2026-05-15T19:10:04.984Z"
description: "Learn how to extract tabular data from PDF documents and images programmatically in C# using Nutrient .NET SDK. Retrieve structured information for analysis."
---

# Extract tables from PDFs and images using C#

Nutrient.NET SDK’s (formerly GdPicture.NET) table extraction engine is a native SDK that enables you to recognize tables in an unstructured document or image, parse the information, and export the tables to an external destination like a spreadsheet. It can detect and extract bordered, semi-bordered, and borderless tables in images, scanned PDFs, and digitally born PDFs. As a native SDK, it can be deployed on-premises or embedded in your application, and it works offline, without internet access.

[Try for Free](https://www.nutrient.io/sdk/dotnet/getting-started.md)

[Launch Demo](https://www.nutrient.io/demo/pdf-table-extraction)

## Extracting table data from a PDF to an Excel spreadsheet

To read and extract table data from a PDF document to an Excel spreadsheet, follow the steps below:

1. Create a `GdPictureOCR` object and a `GdPicturePDF` object.

2. Select the source document by passing its path to the `LoadFromFile` method of the `GdPicturePDF` object.

3. Select the page from which to extract the table data with the `SelectPage` method of the `GdPicturePDF` object.

4. Render the selected page to a 300 dots-per-inch (DPI) image with the `RenderPageToGdPictureImageEx` method of the `GdPicturePDF` object.

5. Pass the image to the `GdPictureOCR` object with the `SetImage` method.

6. Configure the table extraction process with the `GdPictureOCR` object in the following way:
   - Set the path to the OCR resource folder with the `ResourceFolder` property. The default language resources are located in `GdPicture.NET 14\Redist\OCR`. For more information on adding language resources, see the [language support](https://www.nutrient.io/guides/dotnet/ocr/language-support.md) guide.
   - With the `AddLanguage` method, add the language resources that Nutrient.NET SDK uses to recognize text in the image. This method takes a member of the `OCRLanguage` enumeration.

For more optional configuration parameters, see the [`GdPictureOCR` class](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR.html).

7. Run the table extraction process with the `RunOCR` method of the `GdPictureOCR` object, and save the result ID in a list.

8. Create a `GdPictureOCR.SpreadsheetOptions` object and configure the output spreadsheet. By default, tables from the same OCR result are saved in the same sheet. To save each table in a different sheet, set the `SeparateTables` property of the `GdPictureOCR.SpreadsheetOptions` object to `true`. For more optional configuration parameters, see the [`GdPictureOCR.SpreadsheetOptions` class](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR+SpreadsheetOptions.html).

9. Save the output in an Excel spreadsheet with the `SaveAsXLSX` method of the `GdPictureOCR` object. This method takes the following parameters:
   - The list containing the OCR result ID.
   - The path to the output file.
   - The `GdPictureOCR.SpreadsheetOptions` object.

10. Release unnecessary resources.

The example below extracts table data from the first page of a document and saves the output in an Excel spreadsheet:

=

### C#

```csharp

using GdPictureOCR gdpictureOCR = new GdPictureOCR();
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
// Load the source document.
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Select the first page.
gdpicturePDF.SelectPage(1);
// Render the first page to a 300 DPI image.
int imageId = gdpicturePDF.RenderPageToGdPictureImageEx(300, true);
// Pass the image to the `GdPictureOCR` object.
gdpictureOCR.SetImage(imageId);
// Configure the table extraction process.
gdpictureOCR.ResourceFolder = @"C:\GdPicture.NET 14\Redist\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
// Run the table extraction process and save the result ID in a list.
string result = gdpictureOCR.RunOCR();
List<string> resultsList = new List<string>() { result };
// Configure the output spreadsheet.
GdPictureOCR.SpreadsheetOptions spreadsheetOptions = new GdPictureOCR.SpreadsheetOptions()
    {
        SeparateTables = true
    };
// Save the output in an Excel spreadsheet.
gdpictureOCR.SaveAsXLSX(resultsList, @"C:\temp\output.xlsx", spreadsheetOptions);
// Release unnecessary resources.
gdpictureOCR.ReleaseOCRResults();
GdPictureDocumentUtilities.DisposeImage(imageId);
gdpicturePDF.CloseDocument();

```

### VB.NET

```vb

Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    ' Load the source document.
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Select the first page.
    gdpicturePDF.SelectPage(1)
    ' Render the first page to a 300 DPI image.
    Dim imageId As Integer = gdpicturePDF.RenderPageToGdPictureImageEx(300, True)
    ' Pass the image to the `GdPictureOCR` object.
    gdpictureOCR.SetImage(imageId)
    ' Configure the table extraction process.
    gdpictureOCR.ResourceFolder = "C:\GdPicture.NET 14\Redist\OCR"
    gdpictureOCR.AddLanguage(OCRLanguage.English)
    ' Run the table extraction process and save the result ID in a list.
    Dim result As String = gdpictureOCR.RunOCR()
    Dim resultsList As List(Of String) = New List(Of String)()
    resultsList.Add(result)
    ' Configure the output spreadsheet.
    Dim spreadsheetOptions As gdpictureOCR.SpreadsheetOptions = New GdPictureOCR.SpreadsheetOptions() With {.SeparateTables = True
    }
    ' Save the output in an Excel spreadsheet.
    gdpictureOCR.SaveAsXLSX(resultsList, "C:\temp\output.xlsx", spreadsheetOptions)
    ' Release unnecessary resources.
    gdpictureOCR.ReleaseOCRResults()
    GdPictureDocumentUtilities.DisposeImage(imageId)
    gdpicturePDF.CloseDocument()
End Using
End Using

```

=

#### Used methods and properties

- [`AddLanguage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~AddLanguage.html)

- [`CloseDocument`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~CloseDocument.html)

- [`DisposeImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentUtilities~DisposeImage.html)

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`ReleaseOCRResults`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~ReleaseOCRResults.html)

- [`RenderPageToGdPictureImageEx`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~RenderPageToGdPictureImageEx.html)

- [`ResourceFolder`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~ResourceFolder.html)

- [`RunOCR`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~RunOCR.html)

- [`SaveAsXLSX`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~SaveAsXLSX.html)

- [`SelectPage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html)

- [`SetImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~SetImage.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)





## Extracting table data from a PDF to JSON format

To read and extract table data from a PDF document to JSON format, follow these steps:

1. Import the `GdPicture14` and the `Newtonsoft.Json.Linq` namespaces.

2. Create a `GdPictureOCR` object and a `GdPicturePDF` object.

3. Select the source document by passing its path to the `LoadFromFile` method of the `GdPicturePDF` object.

4. Select the page from which to extract the table data with the `SelectPage` method of the `GdPicturePDF` object.

5. Render the selected page to a 300 dots-per-inch (DPI) image with the `RenderPageToGdPictureImageEx` method of the `GdPicturePDF` object.

6. Pass the image to the `GdPictureOCR` object with the `SetImage` method.

7. Configure the OCR process with the `GdPictureOCR` object in the following way:
   - Set the path to the OCR resource folder with the `ResourceFolder` property. The default language resources are located in `GdPicture.NET 14\Redist\OCR`. For more information on adding language resources, see the [language support](https://www.nutrient.io/guides/dotnet/ocr/language-support.md) guide.
   - With the `AddLanguage` method, add the language resources that Nutrient.NET SDK uses to recognize text in the image. This method takes a member of the `OCRLanguage` enumeration.

8. Run the OCR process with the `RunOCR` method of the `GdPictureOCR` object.

9. Get the number of tables detected during the OCR process with the `GetTableCount` method of the `GdPictureOCR` object.

10. Create the JSON object that contains the tables on the page and loop through the tables.

11. For each table, get the number of columns and rows with the `GetTableColumnCount` and `GetTableRowCount` methods of the `GdPictureOCR` object.

12. Create the JSON object that contains the rows in the table and loop through the rows.

13. Create the JSON object that contains the cells in the row and loop through the cells.

14. Get the detected value for each cell with the `GetTableCellText` method of the `GdPictureOCR` object and save it in the JSON object.

15. Print the tables to the console in JSON format.

16. Release unnecessary resources.

The example below extracts table data from the first page of a document and prints the output to the console in JSON format:

=

### C#

```csharp

using GdPicture14;
using Newtonsoft.Json.Linq;...
using GdPictureOCR gdpictureOCR = new GdPictureOCR();
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
// Load the source document.
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Select the first page.
gdpicturePDF.SelectPage(1);
// Render the first page to a 300 DPI image.
int imageId = gdpicturePDF.RenderPageToGdPictureImageEx(300, true);
// Pass the image to the `GdPictureOCR` object.
gdpictureOCR.SetImage(imageId);
// Configure the OCR process.
gdpictureOCR.ResourceFolder = @"C:\GdPicture.NET 14\Redist\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
// Run the OCR process.
string ocrResultId = gdpictureOCR.RunOCR();
// Create the JSON object that contains the tables on the page and loop through the tables.
int tableCount = gdpictureOCR.GetTableCount(ocrResultId);
dynamic[] tables = new JObject[tableCount];
for (int tableIndex = 0; tableIndex < tableCount; tableIndex++)
{
    int columnCount = gdpictureOCR.GetTableColumnCount(ocrResultId, tableIndex);
    int rowCount = gdpictureOCR.GetTableRowCount(ocrResultId, tableIndex);
    // Create the JSON object that contains the rows in the table and loop through the rows.
    dynamic[] rows = new JObject[rowCount];
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
    {
        // Create the JSON object that contains the cells in the row and loop through the cells.
        dynamic[] cells = new JObject[columnCount];
        for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
        {
            cells[columnIndex] = new JObject();
            cells[columnIndex].RowIndex = rowIndex;
            cells[columnIndex].ColumnIndex = columnIndex;
            // Read the content of the cell and save it in the JSON object.
            cells[columnIndex].Text = gdpictureOCR.GetTableCellText(ocrResultId, tableIndex, columnIndex, rowIndex);
        }
        rows[rowIndex] = new JObject();
        rows[rowIndex].Cells = new JArray(cells);
    }
    tables[tableIndex] = new JObject();
    tables[tableIndex].Rows = new JArray(rows);
}
dynamic tablesOnPage = new JObject();
tablesOnPage.Tables = new JArray(tables);
// Print the tables to the console in JSON format.
Console.WriteLine(tablesOnPage.ToString());
// Release unnecessary resources.
gdpictureOCR.ReleaseOCRResults();
GdPictureDocumentUtilities.DisposeImage(imageId);
gdpicturePDF.CloseDocument();

```

### VB.NET

```vb

Imports GdPicture14
Imports Newtonsoft.Json.Linq...
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    ' Load the source document.
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Select the first page.
    gdpicturePDF.SelectPage(1)
    ' Render the first page to a 300 DPI image.
    Dim imageId As Integer = gdpicturePDF.RenderPageToGdPictureImageEx(300, True)
    ' Pass the image to the `GdPictureOCR` object.
    gdpictureOCR.SetImage(imageId)
    ' Configure the OCR process.
    gdpictureOCR.ResourceFolder = "C:\GdPicture.NET 14\Redist\OCR"
    gdpictureOCR.AddLanguage(OCRLanguage.English)
    ' Run the OCR process.
    Dim ocrResultId As String = gdpictureOCR.RunOCR()
    ' Create the JSON object that contains the tables on the page and loop through the tables.
    Dim tableCount As Integer = gdpictureOCR.GetTableCount(ocrResultId)
    Dim tables As Object() = New JObject(tableCount - 1) {}
    For tableIndex = 0 To tableCount - 1
        Dim columnCount As Integer = gdpictureOCR.GetTableColumnCount(ocrResultId, tableIndex)
        Dim rowCount As Integer = gdpictureOCR.GetTableRowCount(ocrResultId, tableIndex)
        ' Create the JSON object that contains the rows in the table and loop through the rows.
        Dim rows As Object() = New JObject(rowCount - 1) {}
        For rowIndex = 0 To rowCount - 1
            ' Create the JSON object that contains the cells in the row and loop through the cells.
            Dim cells As Object() = New JObject(columnCount - 1) {}
            For columnIndex = 0 To columnCount - 1
                cells(columnIndex) = New JObject()
                cells(columnIndex).RowIndex = rowIndex
                cells(columnIndex).ColumnIndex = columnIndex
                ' Read the content of the cell and save it in the JSON object.
                cells(columnIndex).Text = gdpictureOCR.GetTableCellText(ocrResultId, tableIndex, columnIndex, rowIndex)
            Next
            rows(rowIndex) = New JObject()
            rows(rowIndex).Cells = New JArray(cells)
        Next
        tables(tableIndex) = New JObject()
        tables(tableIndex).Rows = New JArray(rows)
    Next
    Dim tablesOnPage As Object = New JObject()
    tablesOnPage.Tables = New JArray(tables)
    ' Print the tables to the console in JSON format.
    Console.WriteLine(tablesOnPage.ToString())
    ' Release unnecessary resources.
    gdpictureOCR.ReleaseOCRResults()
    GdPictureDocumentUtilities.DisposeImage(imageId)
    gdpicturePDF.CloseDocument()
End Using
End Using

```

=

#### Used methods and properties

- [`AddLanguage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~AddLanguage.html)

- [`CloseDocument`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~CloseDocument.html)

- [`DisposeImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentUtilities~DisposeImage.html)

- [`GetTableCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableCount.html)

- [`GetTableRowCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableRowCount.html)

- [`GetTableColumnCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableColumnCount.html)

- [`GetTableCellText`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableCellText.html)

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`ReleaseOCRResults`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~ReleaseOCRResults.html)

- [`RenderPageToGdPictureImageEx`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~RenderPageToGdPictureImageEx.html)

- [`ResourceFolder`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~ResourceFolder.html)

- [`RunOCR`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~RunOCR\(\).html)

- [`SelectPage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html)

- [`SetImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~SetImage.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

## Extracting table data from a PDF to markdown format

To read and extract table data from a PDF document and print it to the console, follow these steps:

1. Create a `GdPictureOCR` object and a `GdPicturePDF` object.

2. Select the source document by passing its path to the `LoadFromFile` method of the `GdPicturePDF` object.

3. Select the page from which to extract the table data with the `SelectPage` method of the `GdPicturePDF` object.

4. Render the selected page to a 300 dots-per-inch (DPI) image with the `RenderPageToGdPictureImageEx` method of the `GdPicturePDF` object.

5. Pass the image to the `GdPictureOCR` object with the `SetImage` method.

6. Configure the OCR process with the `GdPictureOCR` object in the following way:
   - Set the path to the OCR resource folder with the `ResourceFolder` property. The default language resources are located in `GdPicture.NET 14\Redist\OCR`. For more information on adding language resources, see the [language support](https://www.nutrient.io/guides/dotnet/ocr/language-support.md) guide.
   - With the `AddLanguage` method, add the language resources that Nutrient.NET SDK uses to recognize text in the image. This method takes a member of the `OCRLanguage` enumeration.

7. Run the OCR process with the `RunOCR` method of the `GdPictureOCR` object.

8. Get the number of tables detected during the OCR process with the `GetTableCount` method of the `GdPictureOCR` object, and loop through them.

9. For each table, get the number of columns and rows with the `GetTableColumnCount` and `GetTableRowCount` methods of the `GdPictureOCR` object, and loop through them.

10. Get the detected value for each cell with the `GetTableCellText` method of the `GdPictureOCR` object, and print it to the console.

11. Release unnecessary resources.

The example below extracts table data from the first page of a document and prints the output to the console in Markdown syntax:

=

### C#

```csharp

using GdPictureOCR gdpictureOCR = new GdPictureOCR();
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
// Load the source document.
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Select the first page.
gdpicturePDF.SelectPage(1);
// Render the first page to a 300 DPI image.
int imageId = gdpicturePDF.RenderPageToGdPictureImageEx(300, true);
// Pass the image to the `GdPictureOCR` object.
gdpictureOCR.SetImage(imageId);
// Configure the OCR process.
gdpictureOCR.ResourceFolder = @"C:\GdPicture.NET 14\Redist\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
// Run the OCR process.
string ocrResultId = gdpictureOCR.RunOCR();
for (int tableIndex = 0; tableIndex < gdpictureOCR.GetTableCount(ocrResultId); tableIndex++)
{
    int columnCount = gdpictureOCR.GetTableColumnCount(ocrResultId, tableIndex);
    int rowCount = gdpictureOCR.GetTableRowCount(ocrResultId, tableIndex);

    // Print the table to the console.
    Console.Write($"\nTable {tableIndex}");
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
    {
        Console.Write("\n| ");
        for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
        {
            string cellContent = gdpictureOCR.GetTableCellText(ocrResultId, tableIndex, columnIndex, rowIndex).Replace(Environment.NewLine, "");
            Console.Write($" {cellContent} |");
        }
    }
    Console.WriteLine("");
}
// Release unnecessary resources.
gdpictureOCR.ReleaseOCRResults();
GdPictureDocumentUtilities.DisposeImage(imageId);
gdpicturePDF.CloseDocument();

```

### VB.NET

```vb

Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    ' Load the source document.
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Select the first page.
    gdpicturePDF.SelectPage(1)
    ' Render the first page to a 300 DPI image.
    Dim imageId As Integer = gdpicturePDF.RenderPageToGdPictureImageEx(300, True)
    ' Pass the image to the `GdPictureOCR` object.
    gdpictureOCR.SetImage(imageId)
    ' Configure the OCR process.
    gdpictureOCR.ResourceFolder = "C:\GdPicture.NET 14\Redist\OCR"
    gdpictureOCR.AddLanguage(OCRLanguage.English)
    ' Run the OCR process.
    Dim ocrResultId As String = gdpictureOCR.RunOCR()
    For tableIndex As Integer = 0 To gdpictureOCR.GetTableCount(ocrResultId) - 1
        Dim columnCount As Integer = gdpictureOCR.GetTableColumnCount(ocrResultId, tableIndex)
        Dim rowCount As Integer = gdpictureOCR.GetTableRowCount(ocrResultId, tableIndex)
        ' Print the table to the console.
        Console.Write(vbLf & $"Table {tableIndex}")
        For rowIndex = 0 To rowCount - 1
            Console.Write(vbLf & "| ")
            For columnIndex = 0 To columnCount - 1
                Dim cellContent As String = gdpictureOCR.GetTableCellText(ocrResultId, tableIndex, columnIndex, rowIndex).Replace(Environment.NewLine, "")
                Console.Write($" {cellContent} |")
            Next
        Next
        Console.WriteLine("")
    Next
    ' Release unnecessary resources.
    gdpictureOCR.ReleaseOCRResults()
    GdPictureDocumentUtilities.DisposeImage(imageId)
    gdpicturePDF.CloseDocument()
End Using
End Using

```

=

#### Used methods and properties

- [`AddLanguage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~AddLanguage.html)

- [`CloseDocument`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~CloseDocument.html)

- [`DisposeImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentUtilities~DisposeImage.html)

- [`GetTableCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableCount.html)

- [`GetTableRowCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableRowCount.html)

- [`GetTableColumnCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableColumnCount.html)

- [`GetTableCellText`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableCellText.html)

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`ReleaseOCRResults`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~ReleaseOCRResults.html)

- [`RenderPageToGdPictureImageEx`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~RenderPageToGdPictureImageEx.html)

- [`ResourceFolder`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~ResourceFolder.html)

- [`RunOCR`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~RunOCR\(\).html)

- [`SelectPage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html)

- [`SetImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~SetImage.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

## Extracting table data from an image

To read and extract table data from an image, follow these steps:

1. Create a `GdPictureOCR` object and a `GdPictureImaging` object.

2. Select the image of the table by passing its path to the `CreateGdPictureImageFromFile` method of the `GdPictureImaging` object.

3. Configure the OCR process with the `GdPictureOCR` object in the following way:
   - Set the image of the table with the `SetImage` method.
   - Set the path to the OCR resource folder with the `ResourceFolder` property. The default language resources are located in `GdPicture.NET 14\Redist\OCR`. For more information on adding language resources, see the [language support](https://www.nutrient.io/guides/dotnet/ocr/language-support.md) guide.
   - With the `AddLanguage` method, add the language resources that Nutrient.NET SDK uses to recognize text in the image. This method takes a member of the `OCRLanguage` enumeration.

4. Run the OCR process with the `RunOCR` method of the `GdPictureOCR` object.

5. Get the number of tables detected during the OCR process with the `GetTableCount` method of the `GdPictureOCR` object, and loop through them.

6. For each table, get the number of columns and rows with the `GetTableColumnCount` and `GetTableRowCount` methods of the `GdPictureOCR` object, and loop through them.

7. Get the detected value for each cell with the `GetTableCellText` method of the `GdPictureOCR` object, and print it to the console.

8. Release unnecessary resources.

The example below extracts data from the following table and prints the output to the console in Markdown syntax.

[Download the sample table](/images/guides/dotnet/extraction/key-value-pairs/table.png) and run the code below, or [check out our demo](https://www.nutrient.io/demo/data-extraction).

=

### C#

```csharp

using GdPictureOCR gdpictureOCR = new GdPictureOCR();
using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load the source document.
int imageId = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.png");
// Configure the OCR process.
gdpictureOCR.ResourceFolder = @"C:\GdPicture.NET 14\Redist\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
gdpictureOCR.SetImage(imageId);
// Run the OCR process.
string ocrResultId = gdpictureOCR.RunOCR();
for (int tableIndex = 0; tableIndex < gdpictureOCR.GetTableCount(ocrResultId); tableIndex++)
{
    int columnCount = gdpictureOCR.GetTableColumnCount(ocrResultId, tableIndex);
    int rowCount = gdpictureOCR.GetTableRowCount(ocrResultId, tableIndex);

    // Print the table to the console.
    Console.Write($"\nTable {tableIndex}");
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
    {
        Console.Write("\n| ");
        for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
        {
            string cellContent = gdpictureOCR.GetTableCellText(ocrResultId, tableIndex, columnIndex, rowIndex).Replace(Environment.NewLine, "");
            Console.Write($" {cellContent} |");
        }
    }
    Console.WriteLine("");
}
// Release unnecessary resources.
gdpictureImaging.ReleaseGdPictureImage(imageId);
gdpictureOCR.ReleaseOCRResults();

```

### VB.NET

```vb

Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load the source document.
    Dim imageId As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.png")
    ' Configure the OCR process.
    gdpictureOCR.ResourceFolder = "C:\GdPicture.NET 14\Redist\OCR"
    gdpictureOCR.AddLanguage(OCRLanguage.English)
    gdpictureOCR.SetImage(imageId)
    ' Run the OCR process.
    Dim ocrResultId As String = gdpictureOCR.RunOCR()
    For tableIndex As Integer = 0 To gdpictureOCR.GetTableCount(ocrResultId) - 1
        Dim columnCount As Integer = gdpictureOCR.GetTableColumnCount(ocrResultId, tableIndex)
        Dim rowCount As Integer = gdpictureOCR.GetTableRowCount(ocrResultId, tableIndex)
        ' Print the table to the console.
        Console.Write(vbLf & $"Table {tableIndex}")
        For rowIndex = 0 To rowCount - 1
            Console.Write(vbLf & "| ")
            For columnIndex = 0 To columnCount - 1
                Dim cellContent As String = gdpictureOCR.GetTableCellText(ocrResultId, tableIndex, columnIndex, rowIndex).Replace(Environment.NewLine, "")
                Console.Write($" {cellContent} |")
            Next
        Next
        Console.WriteLine("")
    Next
    ' Release unnecessary resources.
    gdpictureImaging.ReleaseGdPictureImage(imageId)
    gdpictureOCR.ReleaseOCRResults()
End Using
End Using

```

=

#### Used methods and properties

- [`AddLanguage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~AddLanguage.html)

- [`CreateGdPictureImageFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~CreateGdPictureImageFromFile.html)

- [`GetTableCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableCount.html)

- [`GetTableRowCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableRowCount.html)

- [`GetTableColumnCount`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableColumnCount.html)

- [`GetTableCellText`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~GetTableCellText.html)

- [`ReleaseGdPictureImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~ReleaseGdPictureImage.html)

- [`ReleaseOCRResults`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~ReleaseOCRResults.html)

- [`ResourceFolder`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~ResourceFolder.html)

- [`RunOCR`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~RunOCR\(\).html)

- [`SetImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureOCR~SetImage.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

Format the output to obtain the following table:

| No. | Museum name                | Location                        | Visits in 2021 | Change since 2020 |
| --- | -------------------------- | ------------------------------- | -------------- | ----------------- |
| 1.  | Louvre                     | France, Paris                   | 2,825,000      | +5                |
| 2.  | Russian Museum             | Russia, Saint Petersburg        | 2,260,231      | +88%              |
| 3.  | Multimedia Art Museum      | Russia, Moscow                  | 2,242,405      | +421%             |
| 4.  | Metropolitan Museum of Art | United States, New York         | 1,958,000      | +84%              |
| 5.  | National Gallery of Art    | United States, Washington, D.C. | 1,704,606      | +133%             |
---

## Related pages

- [Extract data from bank statements using C#](/guides/dotnet/extraction/bank-statements.md)
- [Extract file attachments from PDFs in C#](/guides/dotnet/extraction/file-attachments.md)
- [Extract images from PDFs in C#](/guides/dotnet/extraction/images.md)
- [Effortlessly extract data from PDFs and images](/guides/dotnet/extraction.md)
- [Extract invoice data with C# and OCR](/guides/dotnet/extraction/invoices.md)
- [Check OCR and MICR data extraction using C#](/guides/dotnet/extraction/micr.md)

