Recursive AI

OCR images to a searchable PDF from the command line

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

Combine scanned images into one PDF you can search. The OCR runs locally.

Terminal
dotnet tool install --global RecursiveAI.OneOcr.Tool

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

Terminal
oneocr pdf front.png back.png --out book.pdf

Writes book.pdf in that order. Both PNGs are in the zip.

The command prints this summary (final timing field omitted):

Text
book.pdf: 2 pages, 2 given a text layer, 14 words

The full program

front.png reads “Harbor inventory” and “Canvas sails and brass lanterns.” back.png reads “Workshop inventory” and “Copper fittings and cedar boxes.” Open book.pdf and search for cedar to jump to the second page.

To use the optional C# launcher, unzip the example and run dotnet run in that folder. The launcher installs the pinned tool privately on the first run and prints the same summary as the command above. If you install the global tool yourself, run oneocr pdf directly; you don’t need the launcher.

C#
using System.Diagnostics;
 
// Install a private, pinned copy without changing global tools.
string tools = Path.Combine(AppContext.BaseDirectory, "tools");
string executable = Path.Combine(tools,
    OperatingSystem.IsWindows() ? "oneocr.exe" : "oneocr");
 
if (!File.Exists(executable))
{
    var install = new ProcessStartInfo("dotnet")
    {
        ArgumentList = { "tool", "install", "RecursiveAI.OneOcr.Tool",
            "--version", "1.1.0", "--tool-path", tools },
        RedirectStandardOutput = true
    };
    using var setup = Process.Start(install)!;
    string log = setup.StandardOutput.ReadToEnd();
    setup.WaitForExit();
    if (setup.ExitCode != 0)
    {
        Console.Error.Write(log);
        return setup.ExitCode;
    }
}
 
var command = new ProcessStartInfo(executable)
{
    ArgumentList = { "pdf", "front.png", "back.png", "--out", "book.pdf" }
};
using var run = Process.Start(command)!;
run.WaitForExit();
return run.ExitCode;

If oneocr isn’t found after global installation, open a new terminal or check that your .NET tools directory is on PATH. If OneOcr can’t read an input, it reports the error and exits nonzero.

Variations

Pass a folder instead of naming each image. Move the samples to pages/ and rename them 01-front.png and 02-back.png so sorting by filename gives the desired order. Add --pdfa if you need an archival PDF/A-2b file:

Terminal
oneocr pdf pages --out archive.pdf --pdfa

Starting with a single existing PDF? Replace scan.pdf with the path to your scan:

Terminal
oneocr pdf scan.pdf --out searchable.pdf

The short answer

Run oneocr pdf with the image paths first, followed by --out and the PDF filename. The tool accepts PNG, JPEG and TIFF. It puts the scan on each page and adds invisible, selectable text from its bundled OCR model. Use pdf, not ocr, when you want a PDF rather than a text or JSON file.

How do I combine multiple scanned images into one searchable PDF?

List the filenames in page order as in the recipe, or pass an image folder and OneOcr reads it in filename order. Use zero-padded numbers (01, 02, 10) to make that order predictable instead of relying on how a file manager sorts numbers. Quote a path if it contains spaces. A multi-frame TIFF contributes a page per frame, so two input files do not necessarily mean two output pages.

The output path is required. Use a separate filename from the originals and open the new PDF. Look for a word you expect from the last image to check you reached the last page and got searchable text there. The summary counts pages given a text layer and words written, not whether the spelling is correct. The command documentation lists the supported options and exit codes.

Add --pdfa to request PDF/A-2b instead of a regular PDF. PDF/A is an archival format; OCR is what makes the text searchable. The flag doesn’t change which words the model can recognize. You can use PDF/A-2b for a folder of scans without making an intermediate plain PDF. For a regular searchable PDF, omit the flag.

How can I OCR a PDF on Linux?

Use the same oneocr pdf command with one PDF path instead of image paths. It writes a copy with text layers on pages that need them. Don’t pass two PDFs or mix a PDF and images in one command: use separate invocations for separate PDFs. Existing invisible OCR is replaced by default. Keep it with --keep-ocr-layer only when you trust the original recognition. The operation uses the bundled model; installing the tool uses NuGet, but running the OCR doesn’t need a network connection.

If you’re scripting a batch, check the exit code before moving on. A bad input produces an error rather than a success summary, and the tool only replaces the destination after it has written the whole file. Page notes go to stderr, so the status line on stdout is separate from messages about individual pages.

All oneocr recipes