跳到正文
Skillpedia
PDF、Word 与幻灯片9.5k · #12272

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg-extracting-with-ocr/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 content field, 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, or all.
  • --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=true unless you have a reason.
  • For batch OCR, use xberg batch *.pdf --ocr=true — internal worker pool parallelizes across CPU cores. Cap with --max-concurrent N if 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=true only when pages may be rotated; the classifier adds latency.
  • On Apple Silicon, --acceleration coreml typically 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能