{"data":{"slug":"github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-extracting-with-ocr-fa6bd4c60d9c","title":"Extract Text from Scanned Documents Using OCR","summary":"Extract text from scanned PDFs, photographed pages, or images with no embedded text layer using OCR. Force OCR when extraction returns empty or garbled text.","url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-extracting-with-ocr-fa6bd4c60d9c","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-extracting-with-ocr-fa6bd4c60d9c","markdown_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-extracting-with-ocr-fa6bd4c60d9c.md","download_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-extracting-with-ocr-fa6bd4c60d9c\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure the file is in a supported format (e.g., PDF, JPEG, PNG, TIFF) before running OCR. Use `--force-ocr=true` if the extracted text is empty or garbled.","instructions":"---\ntype: Playbook\ntitle: Extracting With Ocr\ndescription: Use when extracting text from scanned PDFs, photographed pages, or images that have no embedded text layer. Covers OCR backends, language packs, force-OCR, and performance tuning.\nx-ai-rulez:\n  kind: skill\n  id: xberg-extracting-with-ocr\n  metadata:\n    name: xberg-extracting-with-ocr\n---\n\n# Extracting with OCR\n\nUse this when a document is image-based: scanned PDFs, photographed pages,\nscreenshots, JPEG\/PNG\/TIFF with text. Xberg auto-OCRs raster images and\nauto-detects PDFs that lack a text layer. Force it on when extraction\nreturned empty\/garbled text from a PDF that \"looks\" textual.\n\n## When to force OCR\n\n- Extraction returned an empty `content` field, but the file opens visually.\n- The PDF text layer is junk (copy-paste from a viewer produces gibberish).\n- You want consistent output across mixed scanned + digital PDFs.\n\n```bash\nxberg extract scan.pdf --force-ocr=true\nxberg extract scan.pdf --ocr=true --ocr-language eng\n```\n\nIf a page has an unreliable text layer, `--force-ocr=true` re-rasterizes\nand runs OCR on every page.\n\n## Backends\n\nTesseract is the default and ships with the CLI \u2014 no extra install. Other\nbackends are opt-in:\n\n| Backend       | Flag                                  | Install                                          | Notes                                                          |\n| ------------- | ------------------------------------- | ------------------------------------------------ | -------------------------------------------------------------- |\n| Tesseract     | `--ocr-backend tesseract` (default)   | bundled                                          | Best general-purpose, 100+ languages via tessdata.             |\n| PaddleOCR     | `--ocr-backend paddle-ocr`            | bundled (ONNX Runtime)                           | Strong on Asian scripts. Not available on WASM or Windows.     |\n| Candle VLM    | `--ocr-backend candle-trocr` (and other `candle-*`) | bundled (Candle)                  | Local vision OCR models (`candle-trocr`, `candle-paddleocr-vl`, `candle-glm-ocr`, `candle-deepseek-ocr`). |\n| VLM (hosted)  | `--ocr-backend vlm` + `--vlm-model`   | liter-llm provider (`--vlm-api-key`)             | Multimodal LLM via liter-llm. Use when OCR fails on dense or handwritten layouts. |\n\nPick Tesseract first. Switch only when accuracy is unacceptable.\n\n## Language packs\n\nTesseract uses ISO 639-2 codes. Default is `eng`. Combine with `+`:\n\n```bash\nxberg extract menu.jpg --ocr=true --ocr-language \"eng+deu\"\nxberg extract bilingual.pdf --ocr-language \"eng+jpn\"\nxberg extract any.pdf --ocr-language all   # all installed packs\n```\n\nInstall missing packs at the OS level:\n\n```bash\n# macOS\nbrew install tesseract-lang\n\n# Debian\/Ubuntu\nsudo apt install tesseract-ocr-deu tesseract-ocr-jpn tesseract-ocr-fra\n\n# Specific lang only\nsudo apt install tesseract-ocr-<iso639-2>\n```\n\nXberg fails fast with a helpful error if you request a language pack\nthat is not installed. Read the error \u2014 it names the missing file.\n\n## Useful flags\n\n- `--ocr=true` \u2014 enable OCR (auto-enabled for images and scanned PDFs).\n- `--force-ocr=true` \u2014 OCR every page even if a text layer exists.\n- `--disable-ocr=true` \u2014 never OCR; use embedded text where available. Images and image-only pages can return metadata with no recognized text.\n- `--ocr-language <lang>` \u2014 single code or `+`-joined list, or `all`.\n- `--ocr-backend <tesseract|paddle-ocr|vlm|candle-trocr|candle-paddleocr-vl|candle-glm-ocr|candle-deepseek-ocr>` \u2014 pick backend.\n- `--ocr-auto-rotate=true` \u2014 pre-rotate via the auto-rotate model.\n- `--acceleration <cpu|coreml|cuda|tensorrt|auto>` \u2014 ONNX accelerator for\n  paddle-ocr \/ auto-rotate \/ layout models.\n\n## Performance tips\n\n- Cache is on by default. Repeated extraction of the same file + config is\n  instant. Do not pass `--no-cache=true` unless you have a reason.\n- For batch OCR, use `xberg batch *.pdf --ocr=true` \u2014 internal worker\n  pool parallelizes across CPU cores. Cap with `--max-concurrent N` if\n  memory is tight.\n- Raise `--target-dpi` (default 300) only for low-resolution scans. Higher\n  DPI is slower; 200 is usually enough for printed text.\n- Enable `--ocr-auto-rotate=true` only when pages may be rotated; the\n  classifier adds latency.\n- On Apple Silicon, `--acceleration coreml` typically beats CPU for\n  paddle-ocr and layout detection.\n\n## Config file alternative\n\nLong flag chains belong in `xberg.toml` \u2014 auto-discovered from cwd\nupward.\n\n```toml\nforce_ocr = true\noutput_format = \"markdown\"\n\n[ocr]\nbackend = \"tesseract\"\nlanguage = \"eng+deu\"\nauto_rotate = true\n```\n\nThen just run:\n\n```bash\nxberg extract document.pdf\n```\n\n## Common failure modes\n\n- **\"missing tessdata\"** \u2014 install the language pack at OS level (see above).\n- **Empty content on a scanned PDF without `--force-ocr`** \u2014 the file has a\n  bogus zero-width text layer. Re-run with `--force-ocr=true`.\n- **OCR on a rotated page** \u2014 add `--ocr-auto-rotate=true` or pre-rotate.\n- **Garbled CJK output** \u2014 ensure the right language pack is installed and\n  passed via `--ocr-language`; consider `paddle-ocr` for Chinese\/Japanese.\n\nSee `..\/..\/references\/cli-reference.md` and `..\/..\/references\/configuration.md` for the full flag and config schema.\n","use_cases":["Extract text from a scanned PDF that lacks a text layer.","Extract text from a photographed page with no embedded text.","Force OCR on a PDF that returns empty or garbled text."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/xberg-io\/xberg\/blob\/ffbf7971796a126fc52f6bb8fb40418772071f61\/plugin\/.ai-rulez\/skills\/xberg-extracting-with-ocr\/SKILL.md","source_commit":"ffbf7971796a126fc52f6bb8fb40418772071f61","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-15T14:12:33.000000Z","updated_at":"2026-11-16T05:16:54.000000Z","seo_title":"Extract Text from Scanned PDFs with OCR","seo_description":"Use OCR to extract text from scanned PDFs, images, and photographed pages. Force OCR for empty or garbled text extraction results.","seo_keywords":["OCR text extraction","extract text from scanned PDFs","force OCR on PDF","OCR for images","extract text from scanned documents"]}}