432 of 496 pages read locally by choosing per page
Running OCR on a whole document can damage good text and increase cost. This PDF gateway checks each page, reads usable text locally, and sends only 64 of 496 pages to OCR.
Rules in code choose the reading method for each page. In the recorded run, 432 of 496 pages were read locally and only pages flagged by inspection went to OCR.
5 min read
Operational documents include PDFs with usable text, scans, mixed files with a scanned page in the middle, and exports with corrupted text. One reading method cannot handle all of these cases well.
Running OCR on every page adds cost to documents that already contain good text and may reduce its quality. Trusting every text layer has a different risk: an empty or distorted document can continue through the process as if it were correct.
A decision at page level
In the PDF gateway we built, rules in code recognize the file type and flag pages without a usable text layer. The measured corpus contains 172 public PDFs, nine prepared files, and no client data or credentials. The decision happens page by page, so a mixed document is not classified too early or sent to OCR in full.
The system has three outcomes. Pages with correct text are read locally without OCR charges or degradation. Flagged pages go to a local OCR engine that supports Polish and English. A corrupted text layer sends the document to human review with the reason visible.
The operator sees each file's route, time, and cost computed from recorded events, and a public JSON audit lets anyone verify a route without touching the database. Every tool event enters an integrity-protected audit chain.
Defining the three routes
A gate should not ask only whether a page contains any characters. A damaged export can carry a text layer full of nonsense, while a scan may contain a hidden header and still need OCR. Inspection can consider empty-page share, character count and distribution, encoding quality, and images covering most of the page.
Thresholds also depend on document type. An invoice, a contract, and a technical drawing have different expected text densities. A global rule can handle correspondence well and reject valid short certificates. Use document profiles or a conservative review route for unrecognized formats.
Human review is a proper third route. When text looks corrupted and the system cannot establish that recovery preserves layout, numbers, and characters, the document should stop with a visible reason and the affected pages highlighted.
Putting the gateway in front of production
Start by sampling the real document stream and manually labeling pages as native text, scanned, or uncertain. Include mixed files, rotations, multiple languages, password protection, and exports from the most common source systems.
Run the gate in observation mode before changing the route. Classify errors by consequence: unnecessary OCR adds cost, skipped OCR creates missing data, and corrupted text passed downstream can contaminate later automation.
Enable native reading first, OCR for high-confidence scans second, and mixed-document handling last. Preserve the source file and make every route reversible during the rollout.
The measurement
The recorded run covered 181 documents and 496 pages: 172 public PDFs and 9 prepared cases, including reproductions without a text layer and deliberately corrupted text layers. The result: 432 pages were read locally, 14 documents took a partial route, and a corrupted text layer escalated the whole document to review. No page the gateway judged readable went to OCR.
At the stated rate of PLN 0.08 per OCR page, the 64 routed pages cost PLN 5.12 across the full run. A separate small-model document read using gpt-5-mini consumed 2,198 units of model text, took 3.10 seconds, and cost about PLN 0.0035; it does not take part in route selection. The run has no aggregate latency or full operating-cost figure, so those remain deployment measurements.
Calculating cost and quality
The recorded run routed 64 pages to OCR at PLN 0.08 per page, for PLN 5.12. That figure covers OCR only. It excludes storage, local processing, human review, and subsequent extraction. For a first estimate, multiply monthly page volume by the share routed to OCR and the price per page.
Quality needs its own ledger: pages sent to OCR unnecessarily, scans mistaken for native text, documents held for review, and fields corrected after downstream extraction. A lower OCR bill is a poor result if the number of incorrect records increases.
PDF-stream checklist
- Which document types and export systems make up most of the volume?
- What share is mixed, rotated, or contains a corrupted text layer?
- Do the rules assess text quality as well as text presence?
- Are the source file and each page decision retained in the trace?
- Does the operator see why a document reached review?
- Which languages, tables, stamps, and handwriting must OCR handle?
- Does the cost model include review, storage, and downstream extraction?
- Is every threshold change checked against a fixed regression set?
Details and screens on the case page. If your document stream is mixed and the OCR bill keeps growing, a free process scan will show how many pages truly need machine reading.
Free process scan
Start with a free process scan.
- A 30-minute call with the engineer who would lead the work.
- A review of the processes that cost you the most time and money.
- A written summary of what to automate first and the likely cost range.
The scan is free and creates no obligation. If automation is unlikely to pay off, the written recommendation will say so.
€0
30 minutes · written takeaway within 2 business days
Times are shown in your own time zone. We work with clients across time zones.
Describe the process in the form