Using IronOCR with AI Coding Assistants
IronOCR is a commercial OCR library for .NET with more than six million NuGet downloads. Its tutorials, how-to guides, and troubleshooting notes have been public for years, so coding assistants have usually seen it in their training data.
That familiarity does not extend to which release your project pins. An assistant that reads IronOCR's documentation is more likely to write OCR code that builds and returns accurate text. Share the documentation before the first request.
These tools fall into two categories, which differ in how much they do before you review the result.
- An assistant works inside one part of your workflow. It completes a line, explains a method, or makes a small edit, as GitHub Copilot's inline suggestions do.
- An agent takes a multi-step task, edits across files, runs the build and the tests, and commits the result for review, as Claude Code, ChatGPT Codex, Cursor, and Google Antigravity do.
The setup is identical for both. Install the package, apply the license key from an environment variable, provide IronOCR's machine-readable documentation, and check every extracted value against a page whose text you already know. This applies to images and scanned PDFs alike, and to making a scan searchable, reading multiple languages, extracting barcodes from the same read, or improving a low-quality scan.
How to Use IronOCR with an AI Coding Assistant or Agent
- Download the C# OCR library from NuGet
- Load the license key from an environment variable ahead of the first read
- Give the assistant IronOCR's
llms.txtindex before it writes any code - Record the IronOCR rules wherever your assistant keeps project instructions
- Begin a fresh session with the one-shot setup prompt below
- Compile, then check IronOCR's output against the values you expect on each sample page
Can't My AI Assistant Handle OCR on Its Own?
Without documentation, an assistant relies on whatever OCR code it absorbed in training, which often mixes in settings from raw Tesseract wrappers or an earlier IronOCR version.
IronOCR publishes documentation built for tools to read, including tutorials, how-to guides, and more than fifty troubleshooting articles. Once the assistant has loaded it, the documentation shows how IronTesseract, OcrInput, and OcrResult fit together.
Engine selection still matters. Free Tesseract wrappers handle a clean, upright page of English well.
- Readable output does not guarantee correct output: an OCR result can read fluently and still turn 589.50 into 580.50.
OcrResultreports a confidence score for every word to show where to look. - Scans require preparation: crooked, noisy, or low-resolution pages read poorly in any engine.
OcrInputcarries filters that straighten a page, remove noise, raise resolution, and more. - Hand-tuning an engine is costly: each attempt an assistant makes at raw Tesseract settings spends tokens on work the library already does, and the cost recurs with every new document type.
- The package depends on the platform:
IronOcrcovers Windows,IronOcr.MacOscovers Intel Macs, andIronOcr.MacOs.ARMcovers Apple silicon. An assistant can also invent a plausible package name, and attackers register such names with malicious code, a practice called slopsquatting. Name the package in the prompt. - Licensing is predictable: cloud OCR services often bill per page or per call, and an assistant will not mention those terms on its own. IronOCR runs locally under a perpetual commercial license priced in tiers by developers, locations, and projects, with no per-page metering.
Step 1: Install IronOCR
Once the package reference exists, the assistant can see IronOCR's actual types as it generates code.
Install the IronOcr NuGet package into this project and confirm it restores.
The advanced NuGet installation guide lists the other installation options.
Step 2: Apply Your License Key
IronOCR has no watermarked unlicensed mode. Constructing an IronTesseract without a key succeeds, but the first read throws IronSoftware.Exceptions.LicensingException with the message "Production License Required". A key that is present but mistyped produces "License Key Not Recognized" from the same call. You can get a free trial key below.
Start using IronOCR in your project today with a free trial.
Set IronOcr.License.LicenseKey at application startup, before any other IronOCR call, and read it from the IRONOCR_LICENSE_KEY environment variable so that it never enters source control. The same class also has a method that tests a key string without applying it.
Web.config and appsettings.json.Step 3: Point Your Assistant at IronOCR's LLM Documentation
llms.txtis the index, one line per page.- Summaries of 145 pages arrive in one fetch from
llms-full.txt. llms-full-catalog.txtadds the blog to the index.- The API Reference documents every type and member.
- Setup, licensing, recipes, and fixes are in
skill.md. - The AI Product Fact Sheet sums up scope, platforms, and limits.
When a task depends on the detail of one guide, have the assistant open that guide's page.
Provide a direct instruction along with the index.
Before writing any IronOCR code, read https://ironsoftware.com/ocr/csharp/llms.txt
and use only APIs documented there. A read is assembled on an OcrInput, whose
Load overloads differ by source type, and run through IronTesseract.Read.
Confirm the overload you pick against
https://ironsoftware.com/ocr/csharp/object-reference/api/, and if you cannot find
it, say so instead of guessing.
Step 4: Add IronOCR Context to Your Project
Place the IronOCR rules in whichever file your team already keeps. Claude Code reads CLAUDE.md, GitHub Copilot reads .github/copilot-instructions.md, and ChatGPT Codex and Google Antigravity read AGENTS.md. Cursor reads .cursor/rules/*.mdc or AGENTS.md, and only its rule file needs MDC frontmatter. Use the following as a starting point.
## OCR with IronOCR
This project uses IronOCR (NuGet package `IronOcr`, or `IronOcr.Linux` for Linux and Docker, namespace `IronOcr`) for all OCR work.
- Reference: https://ironsoftware.com/ocr/csharp/llms.txt
- Skill file: https://ironsoftware.com/ocr/csharp/skill.md
- Read with `IronTesseract` and an `OcrInput` inside a `using` block, and use the `OcrResult` it returns.
- Read the license key from the IRONOCR_LICENSE_KEY environment variable at startup. Never inline it.
- Every OCR change must be tested against sample pages whose text is known, reporting the values read and their confidence.
- Do not add another OCR engine or a cloud OCR service. If IronOCR cannot do something, say so.
The skill file's single-file example still pins IronOcr 2026.7.2 while NuGet now serves 2026.10.2. It also says to keep every Iron package on the same version, which language packs cannot follow, since IronOcr.Languages.German was last published as 2020.11.2. Its one-line ConvertToSearchablePdf recipe threw on image-only scanned PDFs in our tests, while loading the PDF, reading it, and calling SaveAsSearchablePdf on the result worked.
Step 5: One-Shot Setup Prompt
Everything from Steps 1 through 4 can be sent in a single message.
Use IronOCR for all OCR work in this project.
1. Install the IronOcr NuGet package (IronOcr.Linux when the app runs on Linux or Docker).
2. Apply the license key at application startup, before any other IronOCR call,
reading it from the IRONOCR_LICENSE_KEY environment variable. Never write
the key into source or into a committed file.
3. Read https://ironsoftware.com/ocr/csharp/llms.txt before writing OCR code
and work only from APIs documented there, checking the API reference when a
member is unfamiliar.
4. Load https://ironsoftware.com/ocr/csharp/skill.md if your tooling supports skill files.
5. Keep these instructions for future sessions in this project.
Step 6: Prompt Patterns That Produce Working Code
Weak results usually come from a prompt that leaves the assistant room to guess.
Name the input, the fields, and the language.
Vague Read the invoices with IronOCR.
Better Using IronTesseract with an OcrInput that loads each scanned PDF, read the invoice number and the line starting with Total due, and return the amount with the confidence of that line.
State the release and the framework too.
Better Target .NET 9 with IronOcr 2026.9.4.
Request the whole file.
Better Hand back the complete Program.cs, directives and license setup included, ready to compile without edits.
Step 7: Verify What You Get Back
Watch for these common errors.
- OCR on a PDF that already has text: extracting a real text layer is faster and more accurate than running OCR over the pages. Check for a text layer first and run OCR only on scanned pages.
- Every filter at once: stacking one correction after another on a clean page can lower accuracy and always adds time. On a dense invoice set in our test runs,
DeNoiseturned the final 1 of a rotated invoice number into a 4, and addingDilatecured that page but cost other sets one to three rows. Apply only the filter that fixes the defect you see. IronOCR's skill file gives the same advice, and the image quality correction guide describes when each filter applies.
Let the Agent Verify Its Own Work
Build and run this project in Release. Confirm that every IronOCR member you used
appears in the documentation, that IronOcr.License.IsLicensed returns true, and
that every sample page reads back with the values it is known to contain.
Report the build result and a table of page, expected value, value read, confidence, and match.
How Do You Read Languages Other Than English?
English is the only language in the IronOcr package. IronOCR's language list covers 125. Give the assistant these facts.
- Another language needs its pack, such as
IronOcr.Languages.German, thenLanguage = OcrLanguage.German. - Without NuGet access, use the
.ocrdatafile andInstallation.LanguagePackDirectory. - Fast and Best variants such as
OcrLanguage.GermanFastship in the same package. - For a page in several languages, call
AddSecondaryLanguage, most common first. - Financial tables take
OcrLanguage.FinancialfromIronOcr.Languages.Financial. - A model trained elsewhere loads through
UseCustomTesseractLanguageFilewith a.traineddatafile.
A missing pack raises LanguagePackException on the first read. Its message names the exact NuGet package and the .ocrdata alternative, so have the assistant install what the message names.
IronOCR's fast configuration guide reports a 17% gain from EnglishFast combined with switching barcode reading off. On ten of our pages that variant alone stayed within run-to-run noise of English, so time the variants on your own pages before trading accuracy for speed.
ClickOnce publishing omits the .ocrdata files of secondary languages, as the ClickOnce note explains. On Windows, adding EnglishFast as a secondary language can stall on large PDFs in releases 2025.12.3 through 2026.7.2, as this troubleshooting entry records.
Which IronOCR Settings Are On by Default?
Generated code often sets values that are already defaults, or misses a setting that is off by default. These are the starting values in IronOcr 2026.9.4, read from a fresh IronTesseract.
| Setting | Default | Change it for |
|---|---|---|
Language | English | Other languages |
Configuration.ReadBarCodes | off | Barcodes |
Configuration.ReadDataTables | off | Table structure |
Configuration.RenderSearchablePdf | on | Skipping searchable output |
Configuration.RenderHocr | off | hOCR output |
Configuration.PageSegmentationMode | AutoOsd | Single-line or single-word crops |
Configuration.EngineMode | LstmOnly | Rarely |
Configuration.WhiteListCharacters and BlackListCharacters | empty | Narrow character sets |
Configuration.TesseractVariables | three preset entries | Raw Tesseract variables |
MultiThreaded | on | Rarely |
MaxDegreeOfParallelism | Environment.ProcessorCount | Large batches short of memory |
OcrInput.TargetDPI | 0 | Low-resolution scans |
Beyond the standard read, IronTesseract provides readers tuned for other input. ReadPhoto handles photographs of documents and ReadScreenShot handles screen captures. The specialized documents tutorial still lists IronOcr.Extensions.AdvancedScan for them, but that package last shipped in 2025 and neither reader needed it. The same tutorial also covers the passport and license plate readers.
A Result You Can Reproduce
The prompt
Build a .NET 9 console app that reads totals from scanned invoices. Start in an empty folder; if it already holds code or project files, stop and report. Work start to finish alone: write, build, run, and fix, making sensible assumptions where anything is unspecified. Save every deliverable under the project root, in the folders named below.
1. Install the IronOcr NuGet package pinned to version 2026.9.4.
2. Read https://ironsoftware.com/ocr/csharp/llms.txt and the pages it links to, and use only IronOCR APIs documented there for the OCR work. Any .NET imaging library may draw the test images.
3. Read the license key from the IRONOCR_LICENSE_KEY environment variable at startup and never write it into source or any output file. If IronOcr.License.IsLicensed is false, stop and report that.
4. With random seed 2026, generate testset/invoice-01.png to invoice-10.png. Each is a US Letter page of exactly 1700 x 2200 pixels, saved as PNG with 200 DPI in the file metadata, with all text in Arial inside 0.75 inch margins, headings at 14 point bold and everything else at 11 point. Each invoice has an invoice number made of INV- and six random digits, a customer name, three line items with random prices in dollars and cents, and a total equal to their sum, with no two totals alike.
5. Rotate invoice-02 and invoice-07 by 3 degrees about the page center, keeping the 1700 x 2200 canvas. Add speckle noise to invoice-04 and invoice-09: dark square specks 1 or 2 pixels wide, placed anywhere including over the text, until they have darkened 1% of the page's pixels, counting a pixel as dark below 128 of 255. Leave the other six clean. Write manifest.csv with each file, invoice number, the three prices, total, and distortion (none, rotated, or speckled).
6. Before the first OCR call, check every saved image: 1700 x 2200 pixels, 200 DPI when rounded, and, measured on each page before distortion, the smallest distance from any ink to an edge, at least 0.75 inch. On each speckled page, check that speckling raised the share of dark pixels by 0.9 to 1.1 percentage points. Also draw a capital H with the 11 point font on a 200 DPI bitmap and check that its ink is 21 to 23 pixels tall. If a check fails, fix the generator. After the first OCR call, never regenerate or change the saved image files; filters applied in memory are expected.
7. Read all 10 images in one OcrInput with one set of filters for every page. Each run of the program uses one filter set; it must not try several or choose between them, and choosing filters is your job between runs. No manifest value, file name, or expected value may steer the OCR or the parsing of its text; read the manifest only to write roundtrip.md. The reader must hold no invoice number, price, or total as a literal and must run the same code for every page. Extract each page's invoice number and total, save each page's OCR text as ocr/invoice-01.txt to invoice-10.txt, and save the result as invoices-searchable.pdf.
8. Build in Release and run.
9. Write roundtrip.md: the step 6 checks as measured numbers for every image, not pass or fail words, the filter set used, then a table of file, distortion, expected invoice number, invoice number read, expected total, total read, the Confidence (0 to 100) of the OCR line holding the total or n/a, and match, then the page count of invoices-searchable.pdf loaded back with OcrInput. A row matches only when the invoice number read is identical to the expected one and the total read equals the expected total to the cent.
10. All 10 rows must match and the PDF must have 10 pages. If not, read the saved OCR text of the failing pages, change the filter set or the reader, rebuild, and run again. If rows still fail after eight such runs, stop and report which rows failed, the filter sets tried, and why.
11. Finish with a short report: build result, match count, filters used, font sizes used, and assumptions made.
Output
This is invoice-09, one of the two speckled pages from the run, cropped to the printed area. A plain read matched 8 of 10 invoices and missed both speckled pages, returning this one's invoice number as ANV-938066, and Deskew alone did no better. With DeNoise added, IronOCR returned INV-939066 and 1731.53, at 41.45 confidence on the total line, the lowest of the run. The other speckled total line read at 63.86 and the clean pages at about 95. Claude Code chose those two filters in its first draft and kept them through all five runs of the program.
- An independent check measured every requirement again, and all 10 invoices matched.
- ChatGPT Codex with GPT-6 Luna also matched 10 of 10 on the same prompt.
roundtrip.mdis published unedited and invoice.png at reduced size.
What passes
- The code needed no edits from you.
- Opening any image shows small text with nothing cut off at the edges, and specks on the text as well as the margins.
- Each invoice number and total in
roundtrip.mdalso appears in that page's saved OCR text.
The run record
- The machine runs Windows 11 x64 on a Core i9-14900KF with 64 GB of memory.
- Every project targets .NET 9.
- This guide, Copilot, and Cursor ran
IronOcr2026.9.4, while Claude Code, Codex, and Antigravity ran 2026.10.2. Copilot addedIronOcr.Linux2026.9.4, and Codex, Cursor, and Antigravity addedIronOcr.Languages.German2020.11.2. - Last tested October 8, 2026, with the Cursor run. Every other run is from October 6.
| Guide | Assistant and version | Model | Duration (minutes) |
|---|---|---|---|
| This guide | Claude Code 2.1.277, permission prompts off | Claude Opus 5 | 20.8 |
| Claude Code | Claude Code 2.1.277 | Claude Sonnet 5 | 9.4 |
| ChatGPT Codex | Codex CLI 0.160.0 | GPT-6 Luna | 27.7 |
| GitHub Copilot | Copilot agent mode in VS Code 1.140 | GPT-6 Luna, routed by Auto | 22.0 |
| Cursor | Cursor 3.23.23 desktop app | Grok 4.7 | 83.5 |
| Google Antigravity | Antigravity CLI 1.3.0 | Gemini 3.8 Flash (High) | 32.7 |
Agent-Specific Guides
For steps that suit one tool, open its guide.
- Use IronOCR with Claude Code
- Use IronOCR with ChatGPT Codex
- Use IronOCR with GitHub Copilot
- Use IronOCR with Cursor
- Use IronOCR with Google Antigravity
Troubleshooting
- Apply a License Key in IronOCR
- Improve OCR Accuracy if the recognized text does not match the page
- General OCR Troubleshooting if errors appear after deployment
Questions?
If you have any questions, reach out to support@ironsoftware.com
Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.