---
title: "Scan and OCR PDFs in C# .NET: Accurate text recognition | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/scanning/to-searchable-pdf/"
md_url: "https://www.nutrient.io/guides/dotnet/scanning/to-searchable-pdf.md"
last_updated: "2026-05-14T21:57:26.876Z"
description: "Discover essential OCR scanning methods for .NET, enhancing your application’s document processing capabilities with effective solutions and best practices."
---

# Scan and OCR PDFs in C#

This guide explains how to scan a physical document with a scanner and then save the scanned image in a searchable PDF. Nutrient.NET SDK’s (formerly GdPicture.NET) optical character recognition (OCR) engine enables you to recognize text in an image and then save the text in a PDF. This guide uses the [TWAIN protocol](https://en.wikipedia.org/wiki/TWAIN).

Printing and scanning aren’t supported in the cross-platform.NET 6.0 assembly. For more information, see the [system compatibility](/guides/dotnet/about/system-compatibility.md)  guide.

To get an image from a scanner and then save it in a searchable PDF, follow the steps below:

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

2. Store the handle of the active windows in a variable by calling the `IntPtr.Zero` structure.

3. Select the scanner by passing the handle to the `TwainSelectSource` and the `TwainOpenDefaultSource` methods of the `GdPictureImaging` object.

4. Optional: Hide the scanning user interface with the `TwainSetHideUI` method of the `GdPictureImaging` object. Use this setting when your application cannot communicate with the scanner.

5. Create a new PDF document with the `NewPDF` method of the `GdPicturePDF` object. The parameter of this method sets the conformance level of the PDF document. This parameter is a member of the `PdfConformance` enumeration. For example, use `PDF` to create a common PDF document.

6. Get the image from the scanner by passing the handle to the `TwainAcquireToGdPictureImage` method of the `GdPictureImaging` object.

7. Add the scanned image to a new page in the destination document with the `AddImageFromGdPictureImage` method of the `GdPicturePDF` object.

8. Run the OCR process with the `RunOCR` method of the `GdPictureOCR` object:
   1. Set the code of the language that Nutrient.NET SDK uses to recognize text in the source document. To specify several languages, separate the language codes with the `+` character. For example, `eng+fra`.
   2. Set the path to the OCR resource folder. 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.
   3. Set the character allowlist. When scanning the document, the OCR engine only recognizes the characters included in the allowlist. When you set `""`, all characters are recognized.
   4. Set the dot-per-inch (DPI) resolution the OCR engine uses. It’s recommended to use `300` for the best combination of speed and accuracy.

9. Save the result in a PDF document.

10. Close the TWAIN source handle.

The example below gets an image from a scanner and then saves it in a searchable PDF:

### C#

```csharp

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
// Store the handle of the active windows in a variable.
IntPtr WINDOW_HANDLE = IntPtr.Zero;
// Select the scanner.
gdpictureImaging.TwainSelectSource(WINDOW_HANDLE);
gdpictureImaging.TwainOpenDefaultSource(WINDOW_HANDLE);
// (Optional) Hide the scanning user interface.
gdpictureImaging.TwainSetHideUI(true);
// Create the destination PDF document.
gdpicturePDF.NewPDF(PdfConformance.PDF);
// Get the image from the scanner.
int imageID = gdpictureImaging.TwainAcquireToGdPictureImage(WINDOW_HANDLE);
// Add the scanned image to a new page in the destination document.
gdpicturePDF.AddImageFromGdPictureImage(imageID, false, true);
// Run the OCR process.
gdpicturePDF.OcrPage("eng", @"C:\GdPicture.NET 14\Redist\OCR", "", 300);
// Save the result in a PDF document.
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
// Release unnecessary resources.
gdpictureImaging.ReleaseGdPictureImage(imageID);
gdpictureImaging.TwainCloseSource();

```

### VB.NET

```vb

Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    ' Store the handle of the active windows in a variable.
    Dim WINDOW_HANDLE = IntPtr.Zero
    ' Select the scanner.
    gdpictureImaging.TwainSelectSource(WINDOW_HANDLE)
    gdpictureImaging.TwainOpenDefaultSource(WINDOW_HANDLE)
    ' (Optional) Hide the scanning user interface.
    gdpictureImaging.TwainSetHideUI(True)
    ' Create the destination PDF document.
    gdpicturePDF.NewPDF(PdfConformance.PDF)
    ' Get the image from the scanner.
    Dim imageID As Integer = gdpictureImaging.TwainAcquireToGdPictureImage(WINDOW_HANDLE)
    ' Add the scanned image to a new page in the destination document.
    gdpicturePDF.AddImageFromGdPictureImage(imageID, False, True)
    ' Run the OCR process.
    gdpicturePDF.OcrPage("eng", "C:\GdPicture.NET 14\Redist\OCR", "", 300)
    ' Save the result in a PDF document.
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
    ' Release unnecessary resources.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
    gdpictureImaging.TwainCloseSource()
End Using
End Using

```

#### Used methods

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

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

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

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

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

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

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

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

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

#### Related topics

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

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

## Related pages

- [TWAIN and WIA scanning using C#](/guides/dotnet/scanning.md)
- [Scan and convert files to TIFF in C#](/guides/dotnet/scanning/to-tiff.md)

