IRONSOFTWAREHOME

How to Use IronOCR with ChatGPT Codex

Curtis Chau
Curtis Chau
Updated: October 9, 2026

A common issue in initial AI-assisted OCR attempts is that developers paste incomplete scan importers into a chat, receive seemingly complete code, and later discover misread totals or incorrect configuration calls from other Tesseract wrappers. Such errors are costly with large APIs, as OCR engines with multiple filters, languages, and output formats present many opportunities for mistakes.

IronOCR reads text, barcodes, and table cells from scanned pages directly within your .NET application, locally and without a cloud service.

Quickstart
NuGetInstall with NuGet

PM > Install-Package IronOcr

Install IronOCR by running the command above in the NuGet Package Manager Console, or search for the package in the NuGet Package Manager.

Open Codex in a new console project and specify the desired output, and let Codex select the API calls.

$ironocr Add the IronOcr package, then update Program.cs to turn a scanned
multi-page PDF into a searchable one. Print the page count and the overall
confidence before the file is written. Read the license key from the
IRONOCR_LICENSE_KEY environment variable. Then run dotnet build and fix any
errors.
Text

The $ironocr prefix loads IronOCR's skill.md, saved in the repository as .agents/skills/ironocr/SKILL.md, so Codex reads IronOCR's recipes and known fixes before it writes code.



What is ChatGPT Codex, and how does it fit into .NET OCR work?

ChatGPT Codex is OpenAI's coding agent. It can inspect code, edit files, and run commands in a repository. Install the CLI with npm install -g @openai/codex, as the Codex CLI documentation describes.

Codex's output may vary with each run, even for identical requests. The OCR engine must return the same text for the same scan every time, so use a maintained library and avoid allowing agents to improvise settings.

  • Preprocessing that is already built: skewed and noisy scans need correction before recognition. IronOCR's input object straightens skew, removes noise, and can also binarize and enhance resolution, and the image quality correction guide explains when the noise and resolution filters help.
  • PDFs without a text layer: IronOCR reads scanned PDFs and writes a copy with a real text layer, as the searchable PDF guide shows.
  • More than text: with Configuration.ReadBarCodes turned on, one read returns barcodes and QR codes alongside the text, and table reading is covered in the table reading guide.
  • Ongoing releases: the open-source Tesseract wrapper on NuGet was last updated in November 2022. IronOCR releases updates regularly, as its changelog shows.

What makes an IronOCR prompt effective?

An effective IronOCR prompt names the language and framework, where the code goes, the library version, the input and its fields, the expected output, and the constraints. For an invoice reader, that is C# on .NET 9, Services/InvoiceReader.cs, the IronOcr version in the .csproj, scanned PDF invoices with a Total due line, the total as a decimal with confidence, and no new packages.

Codex relies on its training data and any information you provide, so its knowledge of IronOCR's API may be out of date. OpenAI's research on hallucination traces invented answers to training and evaluation that reward guessing.

Put the OCR rules once in a committed AGENTS.md, which Codex reads before it starts work. IronOCR's llms.txt summarizes each documentation page in a line.

Create AGENTS.md at the repository root with an OCR section stating that this
project uses IronOCR (NuGet package IronOcr, or IronOcr.Linux for Linux and
Docker, namespace IronOcr) for all OCR work, that you must read
https://ironsoftware.com/ocr/csharp/llms.txt before writing OCR code and use only
APIs documented there, that https://ironsoftware.com/ocr/csharp/skill.md should
be loaded if the tooling supports skill files, that the license key comes from
the IRONOCR_LICENSE_KEY environment variable and is never inlined, and that no
other OCR engine or cloud OCR service may be added.
Text

How do you ask Codex to add IronOCR and read a first scanned invoice?

Add the IronOcr NuGet package to this project. Then show me the resulting
PackageReference line from the .csproj and tell me which version was installed.
Do not change any other package references.
Text

The PackageReference line helps identify if an agent installed a different package with OCR or Tesseract in its name.

IronOCR does not offer a watermark mode. Without a license key, the first read throws a LicensingException.

Apply the IronOCR license key at application startup, before any other IronOCR
call, reading it from the IRONOCR_LICENSE_KEY environment variable rather than
hard-coding it. Then confirm IronOcr.License.IsLicensed returns true and tell me
where you put the call.
Text

IronOCR License Keys explains how to get a trial key and lists the configuration files from which IronOCR can read a key.

Create Services/InvoiceReader.cs with a ReadTotal method that takes the path of a
scanned PDF, reads it with IronTesseract, finds the line containing Total due, and
returns the amount as a decimal with that line's confidence, or null when the
line is missing.

Then create Services/SearchablePdf.cs with a Convert method that writes a
searchable copy of a scanned PDF. Build and fix errors.
Text

Codex generated two concise classes. The reader loads the scan into an input object with a using declaration, calls the engine's read method once, and iterates through the result's lines to find the total.

How do you migrate an existing OCR implementation to IronOCR?

Hand this to the explorer agent, since nothing should be written yet.

Imports/LegacyOcrService.cs currently reads scans with another OCR library.

1. List every read it performs, with the settings it uses (language, page
   segmentation, image preprocessing, region, output format).
2. Map each setting to its IronOCR equivalent, citing the documentation page.
3. Do not write any code yet. Wait for my approval on the plan.
Text

If an agent writes 400 lines before you approve the approach, you must review all 400 lines. A mapping table can be corrected with a single response.

After you approve the plan, keep the next request narrowly scoped.

Put the worker agent on the approved plan.

Rewrite LegacyOcrService.cs to use IronOCR, keeping the existing public method
signatures so callers don't change. Before removing the old library, run both
implementations on every page in TestData/known/ and save a table of file,
expected values, and each engine's values to migration-check.md. Remove the old
library only if IronOCR returns the expected values at least as often, and
leave it in Git history only. Build and report the diff.
Text

How do you fix misread values through prompts?

The agent cannot see the paper original, so the prompt has to describe the error and, ideally, include the scans.

I have attached one of the failing scans with codex --image, so look at it
rather than reasoning from file names.

Invoices in TestData/supplier-7/ return totals that are off by one digit in
about a third of cases. The scans are slightly rotated and have speckle from an
old scanner. Clean digital invoices read correctly.

Read InvoiceReader.cs and a sample of the scans. Explain the likely cause before
changing anything, then change the preprocessing only. Do not change how the
total is parsed. Report how many totals match before and after.
Text

Refer to the image orientation correction guide for rotation issues.

Missing languages are the other common case and need the same precision.

German invoices throw LanguagePackException on the first read. Add what IronOCR
needs to read German, prove three German sample invoices return the expected
totals, and link me to the documentation page you used.
Text

Language packs keep their own version numbers. The newest IronOcr.Languages.German is far behind the engine's 2026 releases, so an agent told to keep every Iron package on one version fails the restore until it accepts the mismatch. Say in the repository's agent rules that language packs are exempt.

Which Tesseract settings should you change?

IronOCR provides access to Tesseract's controls through the engine's configuration object, and they help in fewer cases than their descriptions suggest.

Totals in TestData/supplier-7/ now match after the preprocessing change.
Before anything else is tuned, measure the Tesseract settings IronOCR documents
for single fields: a character whitelist, single-line page segmentation, and a
crop to the amount. Apply one at a time on top of the current reader, report
the total read for every page, and keep a setting only if no page gets worse.
Text

Codex kept the whitelist in WhiteListCharacters, which read 9 of 9 totals. PageSegmentationMode set to SingleLine read 0 of 9 and was dropped. A ContentArea crop read 9 of 9 supplier totals but 0 of 3 German, so it went too.

A later refactor combined this reader with a service that also reads invoice numbers, and the whitelist was removed.

In a separate probe on a tight crop around the $9,924.31 total, a whitelisted single-line read returned the right amount, and adding deskew and noise removal left an empty result or a stray 7. Apply filters to the whole page before cropping. Raw Tesseract variables without named properties are set via Configuration.TesseractVariables, a dictionary. Refer to the advanced reading configuration guide for configuration properties and the region guide for cropping.

How do you trace a failure across a whole import or into a container?

Send the explorer agent through the import history first, without writing
anything.

Last month's import read 3,000 scanned invoices, and finance found 45 totals
that do not match the paper. Reprocessing one of those invoices gives the same
wrong total every time.

Investigate:
1. Read ImportService.cs and find how pages are loaded and preprocessed.
2. Identify what the misread invoices have in common.
3. Explain the cause before changing anything.
4. Then propose the minimal fix, and how you will prove the 45 now read correctly.
Text

In our test, an explorer agent found that the importer rasterized pages at 96 DPI and recorded missing totals as $0.00. The agent then reread all 70 restored scans at 300 DPI and recovered 43 of 45, but two remained at zero and one previously correct page failed. The agent recommended a higher-resolution retry only when the first read returns zero. Refer to the DPI settings guide and the confidence guide.

Run this read-only until you have the cause.

This exception is thrown from InvoiceReader.ReadTotal in our Linux Docker
container but not on Windows:

[PASTE FULL EXCEPTION AND STACK TRACE HERE]

Check which IronOCR package the project references and whether it matches the
container's operating system, and whether IRONOCR_LICENSE_KEY reaches the
container. Explain the cause, then propose the change. Don't modify C# code
unless the cause is there.
Text

The container needs the native dependencies the Docker guide lists. That guide still installs IronOcr, which in the tested version ships only Windows native binaries.

How do you turn one-off code into reusable, tested components?

Put the worker agent on this.

Refactor InvoiceReader and SearchablePdf into an InvoiceOcrService registered
with dependency injection. It should read totals and invoice numbers from
scanned PDFs, flag any value whose line confidence is below 80, and produce
searchable copies. Keep the preprocessing choices in one place. Add XML doc
comments. Keep it under 120 lines. Before you finish, run the service over
every folder in TestData/ that has an expected.csv and confirm each total
still matches.
Text
Write xUnit tests for InvoiceOcrService covering: every page in TestData/known/
returns its expected invoice number and total, a page without a total returns
null rather than a guess, a searchable copy has a text layer, and a missing
license key throws a clear exception. Assert on extracted values, not on the
full text of the page.
Text

For the missing-key scenario, test your own guard logic, as IronOCR's licensing exception is not a public type accessible to tests.

Keep recurring IronOCR questions in the repository skill rather than in ~/.codex/prompts/, which OpenAI's custom prompts page marks deprecated.

$ironocr Read the IronOCR API reference for OcrInput and list every method that corrects
image problems, such as rotation, noise, and low resolution, then show which
ones this project already calls.
Text

What did the prompts produce in a real run?

We sent the prompts above to Codex in order, against a sample invoice project. The project is a console application with scanned PDFs, a legacy service using the open-source Tesseract wrapper, and three sets of pages with known values. After the run, an independent Release build, test suite, and probes across all three sets confirmed the results below.

  • Supplier-7 totals rose from 6 of 9 to 9 of 9 with Deskew and DeNoise. Alone, Deskew read 9 of 9 and DeNoise 8 of 9.
  • Both the legacy reader and IronOCR matched 10 of 10 in the migration check.
  • With the German pack, 3 of 3 German totals read correctly and the supplier set stayed at 9 of 9.
  • The 96-line service matched 10 of 10 known, 3 of 3 German and 9 of 9 supplier, and flagged 2 below 80 confidence.
  • Tests passed 13 of 13.
  • Codex ran 14 of 15 prompts with no build errors or manual code edits. The container prompt needs a real Linux stack trace and was not run, and the German samples and import history were added before their prompts.
  • An earlier run failed three ways. Codex reported a 10 of 10 migration without running either engine, a refactor broke a known total, and a settings prompt assumed a filter the reader did not use.

This run's Codex version, model, timing and machine are in the shared run record.

What carries over to the next project?

The AI coding assistants guide adds a single acceptance prompt that takes an assistant from an empty folder to measured results, and the same prompt passed 10 of 10 in Codex during our tests.


Troubleshooting


Questions?

If you have any questions, reach out to support@ironsoftware.com

Curtis Chau
Technical Writer

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.

...
Read More

Ready to Get Started?

Nuget Downloads 6,279,416Version:2026.10just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.10

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.10

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronOCR
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get a Quote, No Obligation
Your details will always be kept confidential.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Trusted by Millions of Engineers Worldwide
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.10

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.10

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999