Turn local PDFs and images into Markdown with Chrome's hidden OCR engine.
No API key. No cloud bill. No model download. Chrome already ships the model; this project calls it directly.
- It reuses Chrome's built-in Screen AI component instead of shipping another OCR model.
- It stays local, so you can process documents without sending them to a cloud API.
- It returns layout-aware Markdown, not just a flat text dump.
- It handles the fast path for text-layer PDFs and only OCRs pages that actually need it.
This project is source-install first.
git clone https://github.com/ayismas/chrome-ocr.git
cd chrome-ocr
pip install -e .[pdf]Check whether Chrome's OCR component is available:
chrome-ocr doctor
python -m chrome_ocr doctorExtract a PDF to Markdown:
chrome-ocr pdf report.pdf -o report.md
chrome-ocr pdf report.pdf --pages 1,3,5-8 --dpi 300OCR an image:
chrome-ocr img scan.png
chrome-ocr img scan.png -o scan.mdfrom chrome_ocr import ocr_img, ocr_pdf
markdown = ocr_pdf("report.pdf")
markdown = ocr_pdf("report.pdf", pages=[1, 3, 5], dpi=300)
text = ocr_img("scan.png")Low-level engine reuse is also available:
from chrome_ocr import ScreenAIEngine, ocr_pdf
engine = ScreenAIEngine()
markdown = ocr_pdf("report.pdf", engine=engine)- PDF to Markdown: direct extraction for text PDFs, OCR fallback for scanned pages.
- Image to Markdown: file paths,
PIL.Image, and NumPy arrays are supported. - Layout-aware output: headings, paragraph breaks, indented blocks, tables, and formulas are reconstructed from geometry.
- Cheap warm runs: the DLL is loaded once per process and reused afterwards.
Reports whether Chrome's chrome_screen_ai.dll is present and whether it initializes correctly.
OCR an image and print Markdown to stdout, or write it to a file with -o.
Extract or OCR a PDF and emit Markdown.
--pagesuses 1-based indexing.--page-sepcontrols how multiple pages are joined.--dpiaffects scanned-page rasterization quality.
Returns only the content extracted from the PDF. It does not inject a file title or page headers.
| Parameter | Type | Default | Description |
|---|---|---|---|
pdf_path |
str |
— | Path to the PDF file |
dpi |
int |
200 |
Rasterization DPI for scanned pages |
pages |
int | list[int] | range | None |
None |
1-based page selection |
page_sep |
str |
"\n\n" |
Separator inserted between pages |
engine |
ScreenAIEngine | None |
None |
Optional reusable engine |
OCR an image to layout-aware Markdown text.
| Parameter | Type | Description |
|---|---|---|
image |
str | Path | PIL.Image | np.ndarray |
Image source |
engine |
ScreenAIEngine | None |
Optional reusable engine |
ocr_img_md is an identical alias.
Advanced API for custom DLL paths and engine reuse across calls.
The repository includes a reproducible benchmark harness so you can generate numbers on your own machine instead of relying on screenshots.
python benchmarks/run_benchmark.py img path/to/scan.png --repeat 5
python benchmarks/run_benchmark.py pdf path/to/report.pdf --repeat 3 --pages 1-5See benchmarks/README.md for methodology and external tool comparisons.
| Requirement | Notes |
|---|---|
| Windows 10 / 11 | chrome_screen_ai.dll is Windows-only |
| Google Chrome | Required for image OCR and scanned / image-only PDFs |
| Python >= 3.9 | Supported in the test matrix |
ocr_pdf()can still extract text-layer PDFs without Chrome Screen AI. The DLL is only required when a page has little or no embedded text and must be OCR'd.
Open Chrome, go to Settings -> Accessibility, enable any screen-reader-related feature, then confirm that this folder exists:
%LOCALAPPDATA%\Google\Chrome\User Data\screen_ai\
The Markdown formatter maps visual structure as follows:
| Visual element | Markdown output |
|---|---|
| Large font (>= 2x body) | # Heading |
| Medium font (1.5-2x body) | ## Heading |
| Slightly larger font (1.25-1.5x body) | ### Heading |
| Indented text | leading spaces |
| Multi-column rows (>= 3 rows) | GFM table |
Formula (content_type=6) |
$$...$$ block |
Chrome ships an accessibility component called chrome_screen_ai.dll.
This library loads the DLL via ctypes, feeds it image data using the SkBitmap memory layout reverse-engineered from Chromium and Skia sources, and decodes the returned VisualAnnotation protobuf without compiling any .proto files.
The bounding-box metadata is then used to reconstruct document structure that most OCR wrappers throw away.
- benchmarks/README.md: reproducible benchmark workflow
- docs/launch-kit.md: maintainer launch copy and post templates
- screen_ai_pdf_parser.py: legacy compatibility wrapper for older imports
pip install -r requirements-dev.txt
pytest tests/ -vTests that require Chrome's DLL are skipped automatically when the component is not installed.
MIT. See LICENSE.
chrome_screen_ai.dll remains part of Google Chrome and subject to Google's terms. This project does not redistribute or modify the DLL.