.NET, no SDK required

OCR C#: Call an OCR API in .NET to Extract Text and Data

Call DocuOCR from C# with the built-in HttpClient: POST a PDF or image, start extraction, and read structured JSON back with named fields, tables and confidence scores. No OCR engine to host, no NuGet SDK to wire, no cloud service account.

The same endpoint reads digital and scanned PDFs and images, so one code path handles them all. Copy the C# below and run it against your own document. Last updated July 2026.

  • HttpClient, JSON out
  • Fields, tables and confidence
  • Reads scans, PDFs and images
  • Webhooks for batch at scale
Try it now, no signup

PDF, JPG, PNG, BMP, HEIC, TIFF

Upload a document to extract

See the JSON your C# would receive, right in the browser.

SOC 2 Type II
256-bit encryption
US data handling
REST and JSON
3 calls
upload, extract, get JSON
0 NuGet
HttpClient is enough
1 endpoint
scans, PDFs and images alike
JSON
fields, tables, confidence
// The short answer

How to run OCR in C#

To run OCR in C#, you send a document to an HTTPS endpoint and read the recognized data back as JSON, all through the HttpClient class that ships with .NET. There is no OCR engine to install, no model to train, and with a REST API like DocuOCR no NuGet package to add. You authenticate with a Bearer API key, POST the file to get a file_id, start an extraction job, then poll or receive a webhook for the result. Because the response is JSON, System.Text.Json deserializes it into a C# record of named fields, table rows and confidence scores you can write straight to a database, a DataTable or an accounting workflow. The same three calls work for a native PDF, a scanned PDF, a photo or a screenshot, so your code does not branch on how the document was made.

The three calls

  • Upload: POST the file, get a file_id.
  • Extract: POST the file_id, get a job hash.
  • Get: poll or webhook for the JSON.
// Copy and run

OCR a PDF in C# with the DocuOCR API

Three HttpClient calls, from a file on disk to structured JSON. Swap in your API key from the dashboard and point it at any PDF or image. Runs on .NET 6 or newer.

OcrPdf.cs
using System.Net.Http.Headers;
using System.Text.Json;

var apiKey = "YOUR_API_KEY";
const string baseUrl = "https://docuocr.com/api/documents";

using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

// 1. Upload the PDF or image, get a file_id
using var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(File.ReadAllBytes("invoice.pdf")), "file", "invoice.pdf");
var upload = await http.PostAsync($"{baseUrl}/upload", form);
var fileId = JsonDocument.Parse(await upload.Content.ReadAsStringAsync())
    .RootElement.GetProperty("file_id").GetString();

// 2. Start extraction, get a job hash
var extract = await http.PostAsJsonAsync($"{baseUrl}/extract", new { file_id = fileId });
var hash = JsonDocument.Parse(await extract.Content.ReadAsStringAsync())
    .RootElement.GetProperty("extraction_hash").GetString();

// 3. Poll until the JSON is ready
JsonElement result;
while (true)
{
    var res = await http.GetStringAsync($"{baseUrl}/extraction/{hash}");
    result = JsonDocument.Parse(res).RootElement;
    if (result.GetProperty("status").GetString() == "completed") break;
    await Task.Delay(2000);
}

// result.GetProperty("fields") and ("tables") are ready to use
foreach (var field in result.GetProperty("fields").EnumerateArray())
    Console.WriteLine($"{field.GetProperty("name")}: {field.GetProperty("value")}");

That is the whole integration. For a production batch, wrap each call in a try or catch block, add a Polly retry policy with exponential backoff on HTTP 429, and register a webhook instead of the polling loop so results arrive as each document finishes. The document OCR API reference covers the full request and response shape.

// .NET support, compared

Every major OCR API's C# NuGet package

The cloud providers ship an official .NET SDK; a REST API needs only HttpClient. What you get back differs more than the language does. Package names verified July 2026 on nuget.org.

OCR API .NET NuGet package What it returns Best for
DocuOCR None (HttpClient, plain REST) Named fields, tables and confidence as JSON Fields plus tables from one call, scans included
Google Cloud Vision Google.Cloud.Vision.V1 Text and bounding boxes, no named fields Raw text OCR on the Google stack
Google Document AI Google.Cloud.DocumentAI.V1 Text plus entities, needs a service account Google-native document pipelines
AWS Textract AWSSDK.Textract Text, forms and tables as blocks AWS-stack teams already using the AWS SDK for .NET
Azure AI Document Intelligence Azure.AI.DocumentIntelligence Text, layout and prebuilt-model fields Azure-stack, prebuilt invoice or receipt models
Azure Vision (image OCR) Azure.AI.Vision.ImageAnalysis Printed and handwritten text from images Reading photos and screenshots on Azure
Mistral Document AI None official (REST; community Mistral.SDK) Markdown plus structured output LLM-based parsing of mixed content
Tesseract Tesseract (charlesw, local, not a hosted API) Plain text only Offline, low-volume, no API cost

The split that matters: raw OCR APIs like Google Cloud Vision return text and coordinates, so you write the field mapping into your own C# model yourself. A document extraction API returns named fields and table rows already, which is most of the code you would otherwise maintain. See the full OCR API pricing comparison for what each costs per 1,000 pages.

// How it works

From a file to a C# record in four steps

1. Authenticate

Generate a key in the dashboard and send it as a Bearer token on the HttpClient default headers.

2. Upload

POST a PDF, PNG, JPG, TIFF or WEBP as multipart form data and read the file_id from the JSON.

3. Extract

POST the file_id to start an async job and get an extraction_hash back.

4. Read JSON

Poll or receive a webhook, then System.Text.Json gives you fields, tables and confidence.

// Where .NET teams use it

What C# developers build on an OCR API

ASP.NET ingestion

A controller or minimal API accepts an upload, posts it to the OCR API, and returns clean structured data to the client with no manual entry.

Accounts payable

A .NET worker service pulls invoices from an inbox or blob container, extracts totals and line items, and posts them to Dynamics, QuickBooks or an ERP.

Table capture

A background job turns scanned statements and reports into rows, then loads them into SQL Server or a DataTable for reporting.

BackgroundService automation

A hosted service classifies and reads documents on upload so the rest of the app receives typed, validated data.

WinForms and WPF apps

A desktop line-of-business app reads scanned forms and screenshots into fields without shipping an OCR engine to every workstation.

Compliance and KYC

A verification flow reads IDs and forms, checks confidence scores, and routes low-confidence values to a reviewer.

// Frequently asked

OCR C# FAQ

How do I use an OCR API in C#?
You call it over HTTPS with the HttpClient class built into .NET. Send your API key as a Bearer token, POST the PDF or image to the upload endpoint, start extraction, then read the JSON back. With DocuOCR that is three short calls and no NuGet package to install: upload returns a file_id, extract returns a job hash, and a GET returns fields, tables and confidence scores as JSON you deserialize with System.Text.Json.
What is the best OCR library for C#?
It depends on whether you want a local library or a hosted API. For offline text from a clean image, the community Tesseract NuGet package (charlesw) wraps the Tesseract engine and runs on your own machine for free. For structured fields and tables from real business documents at volume, a hosted API returns cleaner data with no engine to ship: DocuOCR posts a document and returns named fields and table rows as JSON in one call, while Google, AWS and Azure each publish a .NET SDK and need more wiring.
Is there an official OCR NuGet package?
The cloud providers each ship an official .NET SDK on nuget.org: Google.Cloud.Vision.V1 for Google Cloud Vision, Google.Cloud.DocumentAI.V1 for Document AI, AWSSDK.Textract for AWS Textract, Azure.AI.DocumentIntelligence for Azure (formerly Azure.AI.FormRecognizer), and Azure.AI.Vision.ImageAnalysis for Azure image OCR. Tesseract is a community package, not an official Microsoft one. DocuOCR needs no package at all because it is plain REST called with HttpClient.
Do I need a NuGet package to call an OCR API?
No. A REST OCR API only needs an HTTPS client, and .NET ships HttpClient for that. DocuOCR is called with HttpClient and System.Text.Json, so there is nothing extra to install or keep updated. The cloud providers do publish .NET SDKs, which help if you are already on that cloud but add a dependency, a service-account or key-vault auth model, and their own versioning to track.
How do I OCR a scanned PDF in C#?
Send it to a document OCR API through the same endpoint you use for images. If the PDF has a real text layer the service reads the embedded text, and if it is a scan it runs OCR on the page image. DocuOCR returns the same structured JSON either way, so your C# code does not branch on how the PDF was created. For a purely digital PDF you can also read text locally with a library like PdfPig, but a scan is an image and needs OCR.
How do I handle rate limits and retries in .NET?
Wrap each call in a try or catch block and add exponential backoff on HTTP 429 and 5xx responses, honoring any Retry-After header. In .NET the common pattern is a Polly retry policy on the HttpClient, or a simple loop with Task.Delay. For large batches, push documents through a queue or a bounded Parallel.ForEachAsync rather than one tight loop so you stay under the per-second limit. DocuOCR also supports webhooks, so at scale you register a callback URL instead of polling.
Can a C# OCR API read images and photos?
Yes. A document OCR API reads PNG, JPG, TIFF and WEBP images as well as native and scanned PDFs through the same endpoint. For a photo it runs OCR on the pixels; for a digital PDF it reads the embedded text. DocuOCR returns the same JSON shape for all of them, so a .NET service that ingests mixed uploads gets one consistent response to deserialize.
How much does an OCR API cost from C#?
You pay per page or per document, not per line of code, so the language does not change the price. Raw text OCR runs about $1.50 per 1,000 pages at Azure, AWS and Google, Mistral is $4 per 1,000, and structured extraction runs higher. DocuOCR bills per page on a plan, roughly $14 to $20 per 1,000 pages, with fields and tables included in that rate. A free tier lets you test the .NET integration before you pay.
What does the OCR API return to C#?
JSON, which you deserialize into a C# record or class with System.Text.Json. DocuOCR returns named fields (invoice number, date, totals), table rows with cells in order, and a confidence score on each value so you can flag anything below a threshold for review. Raw OCR APIs like Google Cloud Vision return text and bounding boxes but not named fields, so you write the mapping into your own model yourself.

Ship OCR from .NET this afternoon

Generate an API key, paste the three HttpClient calls above, and read structured JSON back in minutes. No engine to host, no NuGet SDK to learn, and a free tier to test the integration before you pay per page.