Image-only PDF failed? Fix it with OCR and tags
10 of 10
scans passed PDF/UA-1 after OCR and tag-scan.py
Image-only means no text
Acrobat's checker fails a page that is only a photo of text. OCR fixes that: it adds the words as hidden text.
OCR alone still fails the checks
| Way | Passed | Words in the tags |
|---|---|---|
| Our Actor, then LibreOffice | 10 of 10 | 1,286 |
| OCRmyPDF, then tag-scan.py | 10 of 10 | 1,234 |
| Chrome print to PDF | 0 of 10 | 1,149 |
| OCRmyPDF | 0 of 10 | No tags |
| The scan as is | 0 of 10 | No tags |
Words in the tags is the text a screen reader gets from the file's tag tree.
OCRmyPDF found 1,229 words and gave every file a font, which is what Adobe's test looks for. But it adds no tags, so every file still failed 5 rules.
The 5 rules OCR leaves broken
veraPDF named the same failures on every OCRmyPDF file:
- No tag tree, so nothing says what is a heading or a paragraph.
- Text and picture are neither tagged nor marked as background.
- The file does not say that it is tagged.
- Viewers show the file name, not the title.
- No PDF/UA flag in the metadata.
tag-scan.py fixes all 5.
tag-scan.py keeps the scan and adds tags
It tags each OCR line, groups lines into paragraphs and marks the scan as background. It also sets the title, language and PDF/UA flag. The median run took 0.3 seconds a file.
brew install ocrmypdf verapdf
python3 -m venv venv && . venv/bin/activate
pip install pikepdf
ocrmypdf scan.pdf ocr.pdf
python3 tag-scan.py --title "Invoice 1042" --lang en-US ocr.pdf tagged.pdf
verapdf -f ua1 --format text tagged.pdf
The last line prints PASS or FAIL. The file stays PDF/A-2b, as OCRmyPDF made it. Give it a real title. MIT license.
Or rebuild a clean PDF from the text
If it need not look like the scan, rebuild it from our Actor's Markdown with pandoc and the PDF/UA export of LibreOffice.
pandoc -s -M title="Your title" -M lang=en-US --shift-heading-level-by=-1 scan.md -o rebuilt.odt
soffice --headless --convert-to 'pdf:writer_pdf_Export:{"PDFUACompliance":{"type":"boolean","value":"true"}}' rebuilt.odt
All 10 passed, and the files shrank from 1.4 MB to 39 KB on average.
Without the heading shift, 7 of 10 failed one rule: the Actor's headings start at level 2.
Chrome's print to PDF failed all 10: it writes no XMP metadata.
A pass is not the whole check
veraPDF runs only the checks a machine can do. A person must still check reading order, tables and headings: tag-scan.py tags a table as plain lines.
Our Actor read the most words
Our Apify Actor turns scanned PDFs into text or Markdown. Its own code read these 10 scans, and its Markdown gave the most words in the tags.
It gives text, not a PDF. A scanned page costs $0.006, and pages with a text layer are free.
How I tested it
- A made-up letter and invoice in 4 fonts each, and a 2-page letter in 2 fonts. Drawn at 300 dpi with blur, gray paper and noise, saved as JPEG. Renders, not real scans.
- Every way at its defaults. OCRmyPDF ran with no flags. The Actor's code at build 0.1.97 made the Markdown on our Mac.
- Words found in order against the true text. For the tags, Poppler read the tag tree (pdfinfo -struct-text).
- OCRmyPDF claims PDF/A-2b. veraPDF passed 9 of its 10 files: one stream length was off by 1 byte. After tag-scan.py, 10 of 10.
- The printed commands ran as printed on 2 files, with pikepdf from pip. tag-scan.py also passed on OCRmyPDF 17.14.2 files.
- Not tested: Acrobat (paid), PAC (Windows only), screen readers, real scans, color pages, forms, columns.
| Tool | Version | Used for |
|---|---|---|
| veraPDF | 1.30.4 | PDF/UA-1 and PDF/A-2b checks |
| OCRmyPDF | 17.13.0 | OCR, with Tesseract 5.5.4 |
| pikepdf | 10.17.0, 10.18.2 | tag-scan.py |
| pandoc | 3.13 | Markdown to .odt and HTML |
| LibreOffice | 26.8.1 | PDF/UA export |
| Chrome for Testing | 158 | Print to PDF, headless |
| Poppler | 26.03.0 | Words, fonts, images |
Questions people ask
What does Image-only PDF failed mean?
The checker found pages that are pictures with no text. Adobe says its test looks for fonts. Run OCR to add the text, then add tags.
Does OCR make a PDF accessible?
Not alone. OCRmyPDF added the words but no tags, so every test file still failed PDF/UA-1. After tag-scan.py, all 10 passed.
Is there a free PDF accessibility checker for Mac?
Yes: veraPDF. Run brew install verapdf, then verapdf -f ua1 --format text file.pdf. It runs only the checks a machine can do.