Document OCR Skill (docr)
Uses Gemini 2.5 Flash, PaddleOCR, or RapidOCR (local) to recognize text from scanned PDFs and images. Compiled as a single Go binary.
Prerequisites
- - API Key configured in
~/.ocr/config (not needed for Paddle/Rapid) - For RapidOCR engine: INLINECODE1
- For PaddleOCR engine: INLINECODE2
API Key Configuration
Create the config file:
CODEBLOCK0
Quick Start
Path Variable: All commands below use $DOCR. Before running any command, set this variable:
CODEBLOCK1
CODEBLOCK2
Engines
| Engine | Flag | API Key Config | Doc Handling |
|---|
| RapidOCR (default) | INLINECODE4 | None | Local OCR |
| Gemini |
-engine gemini |
gemini_api_key | Cloud Vision API |
|
PaddleOCR (local) |
-engine paddle | None | Local OCR |
CLI Reference
CODEBLOCK3
Installation
We provide pre-compiled binaries to get you started quickly.
CODEBLOCK4
This script will detect your OS (darwin/linux) and architecture (amd64/arm64) and download the appropriate version of docr.
Building from Source (Optional)
If you prefer to build from source, ensure you have Go 1.21+ installed:
CODEBLOCK5
Error Handling
| Error | Solution |
|---|
| INLINECODE13 | Create ~/.ocr/config with API keys |
| INLINECODE15 |
Add
gemini_api_key=VALUE to config |
|
file not found | Verify the document file path |
| API timeout | Retry; large files may need longer |
技能名称: doc-ocr-skills
详细描述:
文档OCR技能 (docr)
使用 Gemini 2.5 Flash、PaddleOCR 或 RapidOCR(本地)从扫描的PDF和图片中识别文本。编译为单个Go二进制文件。
前置条件
- - 在 ~/.ocr/config 中配置API密钥(Paddle/Rapid无需)
- 对于RapidOCR引擎:pip install rapidocr_onnxruntime
- 对于PaddleOCR引擎:pip install paddleocr paddlepaddle
API密钥配置
创建配置文件:
bash
mkdir -p ~/.ocr
cat > ~/.ocr/config << EOF
Google Gemini API密钥
gemini
apikey=your
geminikey
EOF
快速开始
路径变量:以下所有命令均使用 $DOCR。运行任何命令前,请先设置此变量:
bash
SKILL_DIR=$(cd $(dirname ) && pwd)
DOCR=$SKILL_DIR/scripts/docr/docr
bash
使用RapidOCR(默认)识别单个文档
$DOCR document.pdf
$DOCR image.jpg
使用Gemini引擎
$DOCR -engine gemini document.pdf
使用PaddleOCR本地引擎
$DOCR -engine paddle document.pdf
指定输出文件
$DOCR document.pdf -o result.txt
批量处理目录中所有支持的文件
$DOCR -batch ./docs/ -o ./outputs/
引擎
| 引擎 | 标志 | API密钥配置 | 文档处理 |
|---|
| RapidOCR(默认) | -engine rapid | 无 | 本地OCR |
| Gemini |
-engine gemini | gemini
apikey | 云端视觉API |
|
PaddleOCR(本地) | -engine paddle | 无 | 本地OCR |
CLI参考
docr [选项] <文件或目录>
选项:
-engine string OCR引擎:rapid(默认)/ gemini / paddle
-e string 引擎(短标志)
-o string 输出文件路径或目录(批量模式)
-output string 输出路径(长标志)
-batch 批量模式:处理目录中的所有文件
-prompt string 自定义识别提示(gemini)
安装
我们提供预编译的二进制文件,方便您快速上手。
bash
cd doc-ocr-skills/scripts
./install.sh
此脚本将检测您的操作系统(darwin/linux)和架构(amd64/arm64),并下载相应版本的 docr。
从源码构建(可选)
如果您希望从源码构建,请确保已安装 Go 1.21+:
bash
cd doc-ocr-skills/scripts/docr
go build -o docr .
错误处理
| 错误 | 解决方案 |
|---|
| config file not found | 创建包含API密钥的 ~/.ocr/config |
| geminiapikey not found |
在配置中添加 gemini
apikey=VALUE |
| file not found | 验证文档文件路径 |
| API超时 | 重试;大文件可能需要更长时间 |