---
title: "Zonal OCR in C# .NET: Extract data from specific area | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/ocr/zonal/"
md_url: "https://www.nutrient.io/guides/dotnet/ocr/zonal.md"
last_updated: "2026-05-21T17:12:02.207Z"
description: "Learn how to perform zonal optical character recognition (OCR) in C# .NET using Nutrient .NET SDK. Extract text from specific regions of images and PDFs for targeted data retrieval."
---

# Zonal OCR in C# .NET

This guide explains how to use Nutrient.NET SDK’s (formerly GdPicture.NET) optical character recognition (OCR) engine to recognize text in a specific area within your document. This is helpful if you know the exact position of the text in your PDF document or you only want to recognize text in a specific part of the page.

To recognize text in a specific area within a document and then save the result in another document, follow the steps outlined below:

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

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

3. Select the page where you want to recognize text with the `SelectPage` method of the `GdPicturePDF` object.

4. Render the selected page to a 200 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 an element of the `OCRLanguage` enum.
   - Set whether OCR prioritizes recognition accuracy or speed with the `OCRMode` property.
   - Set the character allowlist with the `CharacterSet` property. When scanning the image, the OCR engine only recognizes the characters included in the allowlist.
   - Set the character denylist with the `CharacterBlackList` property. When scanning the image, the OCR engine doesn’t recognize the characters included in the denylist.

7. Set the rectangular area on the page where you want to recognize text. Use the `SetROI` method of the `GdPictureOCR` object with the following parameters:
   1. The distance in pixels between the left edge of the page and the left side of the rectangular area.
   2. The distance in pixels between the top of the page and the top of the rectangular area.
   3. The width of the rectangular area in pixels.
   4. The height of the rectangular area in pixels.

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

9. Save the output in a document.

The example below recognizes text in a specific area on the first page of a document and then saves the result in a TXT file:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
using GdPictureOCR gdpictureOCR = new GdPictureOCR();
// Load the source document.
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Select the first page.
gdpicturePDF.SelectPage(1);
// Render the first page to a 200 DPI image.
int rasterPageID = gdpicturePDF.RenderPageToGdPictureImageEx(200, true);
// Pass the image to the `GdPictureOCR` object.
gdpictureOCR.SetImage(rasterPageID);
// Configure the OCR process.
gdpictureOCR.ResourceFolder = @"C:\GdPicture.NET 14\Redist\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
gdpictureOCR.SetROI(100, 100, 200, 50);
// Run the OCR process.
string resID = gdpictureOCR.RunOCR();
// Save the output in a TXT document.
gdpictureOCR.SaveAsText(resID, @"C:\temp\output.txt", OCROutputTextFormat.Utf16, true);
// Release unnecessary resources.
GdPictureDocumentUtilities.DisposeImage(rasterPageID);
gdpicturePDF.CloseDocument();

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
    ' Load the source document.
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Select the first page.
    gdpicturePDF.SelectPage(1)
    ' Render the first page to a 200 DPI image.
    Dim rasterPageID As Integer = gdpicturePDF.RenderPageToGdPictureImageEx(200, True)
    ' Pass the image to the `GdPictureOCR` object.
    gdpictureOCR.SetImage(rasterPageID)
    ' Configure the OCR process.
    gdpictureOCR.ResourceFolder = "C:\GdPicture.NET 14\Redist\OCR"
    gdpictureOCR.AddLanguage(OCRLanguage.English)
    gdpictureOCR.SetROI(100, 100, 200, 50)
    ' Run the OCR process.
    Dim resID As String = gdpictureOCR.RunOCR()
    ' Save the output in a TXT document.
    gdpictureOCR.SaveAsText(resID, "C:\temp\output.txt", OCROutputTextFormat.Utf16, True)
    ' Release unnecessary resources.
    GdPictureDocumentUtilities.DisposeImage(rasterPageID)
    gdpicturePDF.CloseDocument()
End Using
End Using

```

The example below recognizes phone numbers and addresses in specific areas in a document. It first recognizes numbers in a specific area on the first page of a document. Then, it recognizes any text in another area of the page. Finally, it saves the result in a TXT file:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
using GdPictureOCR gdpictureOCR = new GdPictureOCR();
// Load the source document.
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Select the first page.
gdpicturePDF.SelectPage(1);
// Render the first page to a 200 DPI image.
int rasterPageID = gdpicturePDF.RenderPageToGdPictureImageEx(200, true);
// Pass the image to the `GdPictureOCR` object.
gdpictureOCR.SetImage(rasterPageID);
// Create a list where OCR results are saved.
List<string> results = new List<string>();
// Configure the general settings of the OCR process.
gdpictureOCR.ResourceFolder = @"C:\GdPicture.NET 14\Redist\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
// Configure the OCR process for recognizing the phone number.
gdpictureOCR.Context = OCRContext.OCRContextSingleLine;
gdpictureOCR.CharacterSet = "0123456789";
gdpictureOCR.SetROI(100, 100, 200, 50);
// Run the OCR process to recognize the phone number.
gdpictureOCR.RunOCR("PhoneNumber");
results.Add("PhoneNumber");
// Configure the OCR process for recognizing the address.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock;
gdpictureOCR.CharacterSet = "";
gdpictureOCR.SetROI(300, 100, 200, 200);
// Run the OCR process to recognize the address.
gdpictureOCR.RunOCR("Address");
results.Add("Address");
// Save the output in a TXT document.
gdpictureOCR.SaveAsText(results, @"C:\temp\output.txt", OCROutputTextFormat.Utf16, true);
// Release unnecessary resources.
GdPictureDocumentUtilities.DisposeImage(rasterPageID);
gdpicturePDF.CloseDocument();

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
    ' Load the source document.
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Select the first page.
    gdpicturePDF.SelectPage(1)
    ' Render the first page to a 200 DPI image.
    Dim rasterPageID As Integer = gdpicturePDF.RenderPageToGdPictureImageEx(200, True)
    ' Pass the image to the `GdPictureOCR` object.
    gdpictureOCR.SetImage(rasterPageID)
    ' Create a list where OCR results are saved.
    Dim results As List(Of String) = New List(Of String)()
    ' Configure the general settings of the OCR process.
    gdpictureOCR.ResourceFolder = "C:\GdPicture.NET 14\Redist\OCR"
    gdpictureOCR.AddLanguage(OCRLanguage.English)
    ' Configure the OCR process for recognizing the phone number.
    gdpictureOCR.Context = OCRContext.OCRContextSingleLine
    gdpictureOCR.CharacterSet = "0123456789"
    gdpictureOCR.SetROI(100, 100, 200, 50)
    ' Run the OCR process to recognize the phone number.
    gdpictureOCR.RunOCR("PhoneNumber")
    results.Add("PhoneNumber")
    ' Configure the OCR process for recognizing the address.
    gdpictureOCR.Context = OCRContext.OCRContextSingleBlock
    gdpictureOCR.CharacterSet = ""
    gdpictureOCR.SetROI(300, 100, 200, 200)
    ' Run the OCR process to recognize the address.
    gdpictureOCR.RunOCR("Address")
    results.Add("Address")
    ' Save the output in a TXT document.
    gdpictureOCR.SaveAsText(results, "C:\temp\output.txt", OCROutputTextFormat.Utf16, True)
    ' Release unnecessary resources.
    GdPictureDocumentUtilities.DisposeImage(rasterPageID)
    gdpicturePDF.CloseDocument()
End Using
End Using

```

#### Used methods and properties

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

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

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

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

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

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

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

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

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

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

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

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

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

#### Related topics

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

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

## Related pages

- [C# OCR bank checks to text](/guides/dotnet/ocr/bank-checks.md)
- [C# OCR forms to text](/guides/dotnet/ocr/forms.md)
- [Classify documents in C# .NET](/guides/dotnet/ocr/classify-documents.md)
- [C# OCR ID cards to text](/guides/dotnet/ocr/id-cards.md)
- [C# OCR driver’s licenses to text](/guides/dotnet/ocr/drivers-licenses.md)
- [C# .NET OCR library](/guides/dotnet/ocr.md)
- [C# OCR invoices to text](/guides/dotnet/ocr/invoices.md)
- [C# OCR passports to text](/guides/dotnet/ocr/passports.md)
- [C# OCR MRZ to text](/guides/dotnet/ocr/mrz.md)
- [C# OCR receipts to text](/guides/dotnet/ocr/receipts.md)
- [Supported languages: 100+ OCR language dictionaries](/guides/dotnet/ocr/language-support.md)
- [C# OCR visas to text](/guides/dotnet/ocr/visas.md)
- [Create custom OCR parameters in C#](/guides/dotnet/ocr/parameters.md)

