xberg-extracting-with-ocr
它能做什么
这项技能说明如何使用 OCR 从基于图像的文档中提取文字。适合有扫描的纸质材料、拍摄的页面或截图的人。
适用场景
- ✓当你有一份扫描的 PDF 或一张页面照片,需要其中的文字时。
- ✓当 PDF 提取结果为空或乱码,但在屏幕上看起来可以阅读时。
- ✓当你需要另一种语言文档中的文字,并必须设置语言时。
技能链接
https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg-extracting-with-ocr/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请提取这份扫描合同 PDF 中的文字,合同使用的是西班牙语。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会开启 OCR;当文字层质量较差时,则会强制对每一页进行 OCR。默认使用内置的 Tesseract 引擎,并可设置用于识别的语言。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Extracting with OCR
Use this when a document is image-based: scanned PDFs, photographed pages, screenshots, JPEG/PNG/TIFF with text. Xberg auto-OCRs raster images and auto-detects PDFs that lack a text layer. Force it on when extraction returned empty/garbled text from a PDF that "looks" textual.
When to force OCR
- Extraction returned an empty
contentfield, but the file opens visually. - The PDF text layer is junk (copy-paste from a viewer produces gibberish).
- You want consistent output across mixed scanned + digital PDFs.
xberg extract scan.pdf --force-ocr=true
xberg extract scan.pdf --ocr=true --ocr-language eng
If a page has an unreliable text layer, --force-ocr=true re-rasterizes
and runs OCR on every page.
Backends
Tesseract is the default and ships with the CLI — no extra install. Other backends are opt-in:
| Backend | Flag | Install | Notes |
|---|---|---|---|
| Tesseract | --ocr-backend tesseract (default) |
bundled | Best general-purpose, 100+ languages via tessdata. |
| PaddleOCR | --ocr-backend paddle-ocr |
bundled (ONNX Runtime) | Strong on Asian scripts. Not available on WASM or Windows. |
| 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). |
| 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. |
Pick Tesseract first. Switch only when accuracy is unacceptable.
Language packs
Tesseract uses ISO 639-2 codes. Default is eng. Combine with +:
xberg extract menu.jpg --ocr=true --ocr-language "eng+deu"
xberg extract bilingual.pdf --ocr-language "eng+jpn"
xberg extract any.pdf --ocr-language all # all installed packs
Install missing packs at the OS level:
# macOS
brew install tesseract-lang
# Debian/Ubuntu
sudo apt install tesseract-ocr-deu tesseract-ocr-jpn tesseract-ocr-fra
# Specific lang only
sudo apt install tesseract-ocr-<iso639-2>
Xberg fails fast with a helpful error if you request a language pack that is not installed. Read the error — it names the missing file.
Useful flags
--ocr=true— enable OCR (auto-enabled for images and scanned PDFs).--force-ocr=true— OCR every page even if a text layer exists.--disable-ocr=true— never OCR; use embedded text where available. Images and image-only pages can return metadata with no recognized text.--ocr-language <lang>— single code or+-joined list, orall.--ocr-backend <tesseract|paddle-ocr|vlm|candle-trocr|candle-paddleocr-vl|candle-glm-ocr|candle-deepseek-ocr>— pick backend.--ocr-auto-rotate=true— pre-rotate via the auto-rotate model.--acceleration <cpu|coreml|cuda|tensorrt|auto>— ONNX accelerator for paddle-ocr / auto-rotate / layout models.
Performance tips
- Cache is on by default. Repeated extraction of the same file + config is
instant. Do not pass
--no-cache=trueunless you have a reason. - For batch OCR, use
xberg batch *.pdf --ocr=true— internal worker pool parallelizes across CPU cores. Cap with--max-concurrent Nif memory is tight. - Raise
--target-dpi(default 300) only for low-resolution scans. Higher DPI is slower; 200 is usually enough for printed text. - Enable
--ocr-auto-rotate=trueonly when pages may be rotated; the classifier adds latency. - On Apple Silicon,
--acceleration coremltypically beats CPU for paddle-ocr and layout detection.
Config file alternative
Long flag chains belong in xberg.toml — auto-discovered from cwd
upward.
force_ocr = true
output_format = "markdown"
[ocr]
backend = "tesseract"
language = "eng+deu"
auto_rotate = true
Then just run:
xberg extract document.pdf
Common failure modes
- "missing tessdata" — install the language pack at OS level (see above).
- Empty content on a scanned PDF without
--force-ocr— the file has a bog
常见问题
OCR 需要额外的软件吗?
Tesseract 默认随工具提供,因此基本使用无需额外安装。其他 OCR 引擎是可选的。
什么是强制 OCR?
它表示即使页面中有部分嵌入文字,每一页也都会使用 OCR 进行识别。
支持哪些语言?
Tesseract 通过语言数据文件支持 100 多种语言。
详情
作者的原始描述
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.
repo: xberg-io/xberg
热度
- GitHub 星标
- 9.5k
- 排名
- #12272
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
xberg-batch-extraction
9.5k帮你的智能体使用 Xberg 一次处理大量文档,共用一组选项,限制并行工作量,并让失败的文件不会中断整个任务。
xberg-chunking
9.5k帮你的智能体把长文档文字切分为较小的片段,用于 AI 提示或搜索索引,可设置大小并可选择重叠部分。
xberg-extracting-keywords
9.5k帮你的智能体使用 Xberg 的关键词设置,从文档中提取主要关键词或关键短语,并检测文档语言。
xberg-extracting-tables
9.5k帮你的智能体从 PDF、电子表格和图片中提取表格,并以 Markdown 或结构化数据的形式保持行和列的完整。