---
title: "Make a scanned PDF searchable in C#"
url: https://recursiveai.org/oneocr/cookbook/make-scanned-pdf-searchable/
description: "Make a scanned PDF searchable in C# with local OCR. Add selectable text without changing how the pages look, or write a searchable PDF/A-2b copy."
version: "1.1.0"
---

# Make a scanned PDF searchable in C#

**OneOcr** is a free, open-source OCR library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneOcr.Pdf) · [GitHub](https://github.com/recursive-ai-oss/oneocr-csharp) · [Docs](https://recursiveai.org/oneocr/docs/) · [Download example (.zip)](https://recursiveai.org/oneocr/cookbook/make-scanned-pdf-searchable/make-scanned-pdf-searchable.zip)

Add invisible text so you can search and copy words from the scan.

```shell
dotnet add package RecursiveAI.OneOcr.Pdf
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneOcr;
using OneOcr.Pdf;

var engine = OcrEngine.LoadBundled();
SearchablePdf.MakeSearchable(
    "scan.pdf", "searchable.pdf", engine);
```

Writes `searchable.pdf` without printing anything. Use your own `scan.pdf` or the one in the zip.

Unzip [the example](https://recursiveai.org/oneocr/cookbook/make-scanned-pdf-searchable/make-scanned-pdf-searchable.zip), then `dotnet run`.

## The full program

The example includes an image-only PDF. It shows “Harbor inventory” and “Canvas sails and brass lanterns.” The program also reports how much text it added.

```csharp
using OneOcr;
using OneOcr.Pdf;

var engine = OcrEngine.LoadBundled();
var result = SearchablePdf.MakeSearchable(
    "scan.pdf", "searchable.pdf", engine);

Console.WriteLine($"Added layers: {result.PagesWithTextLayer}");
Console.WriteLine($"Words written: {result.WordsWritten}");
foreach (string note in result.Diagnostics)
    Console.Error.WriteLine(note);
```

```text
Added layers: 1
Words written: 7
```

Open `searchable.pdf` in your PDF reader and search for `lanterns`. If the input PDF is damaged, `MakeSearchable` can throw `OcrFormatException`.

## Variations

[PDF/A](https://www.loc.gov/preservation/digital/formats/fam/fdd000318.shtml) is an archival PDF standard; use this variation when your records system requires PDF/A-2b. Replace the `var result = SearchablePdf.MakeSearchable(...)` statement in the full program with:

```csharp
var archive = new SearchablePdfOptions
{
    Conformance = SearchablePdfConformance.PdfA2b
};
var result = SearchablePdf.MakeSearchable(
    "scan.pdf", "archive.pdf", engine, archive);
```

If your scan is an image rather than a PDF, use `ToSearchablePdf` instead. The zip includes `page.png`, the same inventory as a PNG. Replace that same statement with the following. `OneImage` comes with the PDF package.

```csharp
var image = OneImage.Image.Load("page.png");
var result = image.ToSearchablePdf(
    engine, "from-image.pdf");
```

## Related recipes

- [Create a searchable PDF from images at the command line](https://recursiveai.org/oneocr/cookbook/oneocr-pdf-command-line/)
- [OCR a PDF in C# without writing a new PDF](https://recursiveai.org/oneocr/cookbook/ocr-pdf/)

## The short answer

Use `SearchablePdf.MakeSearchable` from `RecursiveAI.OneOcr.Pdf` when you already have a scanned PDF and want another PDF you can search. The bundled OCR (optical character recognition) engine reads the scan locally. It writes recognized words at the positions where they appear, as invisible text over the original page. You don’t need to export the PDF pages to image files first.

## Why is a scanned PDF not searchable?

A scanner can save a photograph of each page inside a PDF. The letters are just pixels. A PDF reader can show the page, but its Find command has no text to look through. A PDF can also contain a mix: for example, a digital cover sheet with selectable text followed by scanned attachments. Try selecting a word on the page you care about, not just on the first page.

OneOcr adds a text layer rather than replacing the image with typeset text. In the [searchable PDF specification](https://recursiveai.org/oneocr/docs/searchable-pdf/), each recognized word has a position and a frame based on its line. That gives the PDF reader text to highlight over the corresponding words. The scan still shows the original printed text, even when OCR misreads it.

## Can I make a scanned PDF searchable if some pages already have text?

Yes. In normal PDF output, `MakeSearchable` leaves pages with trusted text alone and adds a layer where it recognizes words from pixels. It doesn’t needlessly turn an already searchable cover sheet into an image. An invisible layer left by an earlier OCR run is normally replaced rather than stacked under a second copy of the same words. Set `PdfOcrOptions.TrustExistingOcrLayer` through `SearchablePdfOptions.Pdf` if you know you want to keep those layers.

`PagesWithTextLayer` counts pages that received new text; it doesn’t count pages that were searchable already. A zero count can therefore mean nothing needed adding, or that nothing was recognized. Check the result’s diagnostics and try searching the output before discarding or replacing an original. If you only need text and word positions for your application, `PdfOcr.Read` returns those without writing another PDF.

## Why isn’t my PDF OCR recognizing text?

First check whether the words are legible in the original at normal zoom. Blurred letters and faint characters can still look like words to a person but be misread in the invisible layer. Search for a few distinctive words from different pages and copy a line into a text editor; they tell you more than the page count alone. The bundled OneOcr recognizer is for printed Latin, Greek and Cyrillic text. Don’t count on it to make handwritten notes or unsupported scripts searchable. If you have a clearer scan, run OCR on that copy rather than repeatedly recognizing the same poor image.
