How OCR text layers are stored in PDF
Tr 3 in PDF content stream syntax — "invisible text"). The text characters are positioned to align with the corresponding glyphs in the scan image, but they are rendered with zero opacity. This allows text selection, search, and extraction to work on the positioned invisible text while the visible rendering comes from the image.
Glyph positioning precision — High-quality OCR tools position each recognised character precisely over its scan location. Lower-quality tools may position text at line level rather than character level, which affects copy-paste accuracy and accessibility — a screen reader that reads the text layer gets the right words but potentially in wrong order if line positioning is imprecise.
Font embedding in OCR output — OCR text layers use embedded fonts. Since the text is invisible, font appearance doesn't matter, but the font must be embedded for PDF/A compliance. Many OCR tools use a generic CIDFont for the text layer. The /ToUnicode CMap must map every glyph to its Unicode code point — without it, text extraction works visually but copy-paste fails. See PDF Font Embedding for more on /ToUnicode requirements.
Searchable PDF vs text-only PDF — "Searchable PDF" is OCR terminology for the image-plus-text-layer result. It is distinct from a "text PDF" generated directly from a word processor, where text is rendered visibly from font outlines. In a searchable PDF, visual rendering is always the scan image — the text layer is only there for machine access.OCR accuracy: factors and measurement
OCR tools: Tesseract, Acrobat, and cloud APIs
tesseract input.pdf output pdf produces a searchable PDF. Python integration via pytesseract or via ocrmypdf (which wraps Tesseract for PDF-specific workflows with PDF/A output support). github.com/tesseract-ocr/tesseract
ocrmypdf — A Python command-line tool specifically for adding OCR text layers to existing PDFs. It wraps Tesseract, handles multi-page PDFs, optionally produces PDF/A-1b or PDF/A-2b output, deskews images, cleans scans, and validates output. ocrmypdf.readthedocs.io
Adobe Acrobat Pro OCR — Acrobat's "Recognise Text" function uses Adobe's OCR engine. Strong on complex layouts and produces well-structured text layers. Integration with Acrobat's PDF/A conversion workflow makes it suitable for archiving pipelines. Best for desktop workflows with moderate volumes.
Cloud OCR APIs:
- AWS Textract: Extracts text, tables, and form fields from scanned documents. Particularly strong on forms. Returns structured data (key-value pairs for forms, cell data for tables) not just plain text.
- Google Document AI: High accuracy across document types, strong multilingual support, specialised processors for invoices, identity documents, and lending forms.
- Azure Document Intelligence (formerly Form Recognizer): Similar capability profile. Preferred in Microsoft-stack organisations.
Cloud APIs are best for high-volume, automated pipelines where cost per page is acceptable (typically $0.001–$0.01 per page). For on-premises processing of sensitive documents, Tesseract/ocrmypdf remains the standard.OCR for PDF/A archiving and accessibility
ocrmypdf --output-type pdfa-1 produces PDF/A-1b compliant output using Ghostscript for the conversion step.
PDF/A-2a for accessible OCR — To produce an accessible, tagged searchable PDF from a scan, OCR alone is insufficient — you also need to tag the text layer with semantic structure (/P paragraphs, /H1–H6 headings, etc.). This is difficult because OCR engines typically output a flat text layer without structure. Tools like ABBYY FineReader and commercial remediation tools can produce tagged OCR output. For most scanned archive workflows, PDF/A-1b (searchable but not tagged) is the practical target.
Validation after OCR — Always validate OCR output:
1. Open the PDF and use Ctrl+F (Find) to search for a known word — confirms the text layer is present and searchable.
2. Copy-paste a paragraph and check it against the original — confirms /ToUnicode mapping is correct.
3. Run pdffonts to verify font embedding.
4. For PDF/A, validate with veraPDF.