Xuan-You Lin

Pdf Ocr Tool

办公效率v1.3.0
作者:Xuan-You Lin更新于 2026-05-17共 3 个版本 · 最新版本发布于 2026-02-26pdf-ocr-tool@clawhub_tsukisama9292/pdf-ocr-tool
PDF 处理#OCR#PDF

据 AlphaMoat 统计,截至 2026-09,Pdf Ocr Tool 累计下载 2,845 次、获 1 个星标,在全部 5,078 个 AI 技能中排名第 3,835 位,在「办公效率」分类(435 个)中排名第 285 位。

累计安装
447
累计下载
2,845
星标
1
全站排名
#3,835
全站前 76% · 「办公效率」前 66%
平台累计安装累计下载星标评论
ClawHub ↗391,415--
SkillHub ↗4472,8451—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

支持文字、表格、图形与混合模式,可逐页处理或分区识别,并可保存图像区域。需 Ollama 模型、uv 及 PDF 转图工具;结果质量受输入清晰度和提示词影响,应核对识别内容。

资料发布于 2026-10-27

可以用来做什么

  • 提取扫描文档中的文字与表格

什么时候用

  • 需要将PDF或图像整理为结构化Markdown时

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

识别这份文档的文字和表格,保留分页,并标出需要人工复核的内容。

月度数据趋势

累计下载2,845
8461,9202,9932026-03 · 累计下载 9942026-05 · 累计下载 1,5382026-06 · 累计下载 1,7442026-07 · 累计下载 2,0082026-08 · 累计下载 2,1982026-09 · 累计下载 2,84526-0326-09
星标1
0112026-03 · 星标 -2026-05 · 星标 12026-06 · 星标 12026-07 · 星标 12026-08 · 星标 12026-09 · 星标 126-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-092,845—1
2026-082,198+9.5%1
2026-072,008+15.1%1
2026-061,744+13.4%1
2026-051,538—1
2026-03994—-

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

7.5 KB · ClawHub v1.3.0
---
name: pdf-ocr-tool
description: Intelligent PDF and image to Markdown converter using Ollama GLM-OCR with smart content detection (text/table/figure)
metadata: {"openclaw":{"emoji":"📄","requires":{"bins":["uv","ollama","pdftoppm"],"anyBins":[],"env":[],"config":[]},"install":[{"id":"uv-env","kind":"uv","path":".","bins":["ocr_tool.py"]}]}}
---
# PDF OCR Tool - Intelligent PDF to Markdown Converter

Uses the Ollama GLM-OCR model to intelligently recognize text, tables, and figures in PDF pages, applying the most appropriate prompts for OCR processing and outputting structured Markdown documents.

## Features
展开全部(共 301 行)

- ✅ **Smart Content Detection**: Automatically identifies page content type (text/table/figure)
- ✅ **Mixed Mode**: Splits pages into multiple regions for processing different content types
- ✅ **Multiple Processing Modes**: Supports text, table, figure, mixed, and auto modes
- ✅ **PDF Page-by-Page Processing**: Converts PDF to images and processes each page
- ✅ **Image OCR**: Supports OCR for single images
- ✅ **Custom Prompts**: Adjustable OCR prompts based on requirements
- ✅ **Flexible Configuration**: Customizable Ollama host, port, and model
- ✅ **uv Package Management**: Uses uv for Python dependency management

## Installation

### 1. Prerequisites

```bash
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
ollama pull glm-ocr:q8_0

# Install poppler-utils (for PDF to image conversion)
sudo apt install poppler-utils  # Debian/Ubuntu
brew install poppler            # macOS

# Install uv package manager
curl -LsSf https://astral.sh/uv/install.sh | sh
```

### 2. Install with uv (Recommended)

```bash
cd skills/pdf-ocr-tool
uv venv
source .venv/bin/activate
uv add requests Pillow
```

### 3. Install via ClawHub

```bash
npx clawhub install pdf-ocr-tool
```

### 4. Manual Installation

```bash
# Clone or download skill
git clone <repo> ~/.openclaw/workspace/skills/pdf-ocr-tool

# Create virtual environment and install dependencies
cd ~/.openclaw/workspace/skills/pdf-ocr-tool
uv venv
source .venv/bin/activate
uv add requests Pillow

# Run post-install script
bash hooks/post-install.sh
```

## Usage

### Basic Usage

```bash
# Auto-detect content type (recommended)
python ocr_tool.py --input document.pdf --output result.md

# Specify processing mode
python ocr_tool.py --input document.pdf --output result.md --mode text
python ocr_tool.py --input document.pdf --output result.md --mode table
python ocr_tool.py --input document.pdf --output result.md --mode figure

# Mixed mode: split page into regions
python ocr_tool.py --input document.pdf --output result.md --granularity region

# Process a single image
python ocr_tool.py --input image.png --output result.md --mode mixed
```

### Advanced Configuration

```bash
# Specify Ollama host and port
python ocr_tool.py --input document.pdf --output result.md \
  --host localhost --port 11434

# Use different model
python ocr_tool.py --input document.pdf --output result.md \
  --model glm-ocr:q8_0

# Custom prompt
python ocr_tool.py --input image.png --output result.md \
  --prompt "Convert this table to Markdown format, keeping rows and columns aligned"

# Save figure region images
python ocr_tool.py --input document.pdf --output result.md --save-images
```

### Environment Configuration

```bash
# Set default configuration
export OLLAMA_HOST="localhost"
export OLLAMA_PORT="11434"
export OCR_MODEL="glm-ocr:q8_0"

# Run
python ocr_tool.py --input document.pdf --output result.md
```

## Processing Modes

| Mode | Description | Use Case |
|------|-------------|----------|
| `auto` | Auto-detect content type | General use (default) |
| `text` | Pure text recognition | Academic papers, articles, reports |
| `table` | Table recognition | Data tables, financial reports |
| `figure` | Chart/figure recognition | Statistical charts, flowcharts, diagrams |
| `mixed` | Mixed mode | Pages with multiple content types |

### Mixed Mode (Granularity)

When using `--granularity region`:
- Page is split vertically into multiple regions (default: 3)
- Each region is independently analyzed for content type
- Corresponding prompts are used for OCR
- Final results are combined into complete Markdown

## Output Format

### PDF Output Example

```markdown
# PDF to Markdown Result
**Total Pages**: 15
**Model**: glm-ocr:q8_0
**Mode**: auto
**Generated**: 2026-02-27T01:00:00+08:00

---

## Page 1
*Type: mixed*

### Region 1 (text)
[OCR recognized text content]

### Region 2 (table)
<table>
<tr><th>Column 1</th><th>Column 2</th></tr>
<tr><td>Data 1</td><td>Data 2</td></tr>
</table>

### Region 3 (figure)
[Chart description]
![Chart](./images/page_1_region_3.png)

---
```

### Image Output Example

```markdown
# image.png OCR Result
Model: glm-ocr:q8_0
Mode: table

---

[OCR recognized result]
```

## Prompt Templates

The tool includes four built-in prompt templates in the `prompts/` directory:

### Text Mode (`prompts/text.md`)
```
Convert the text in this region to Markdown format.
- Preserve paragraph structure and heading levels
- Handle lists correctly
- Preserve mathematical formulas
- Maintain citations and references
```

### Table Mode (`prompts/table.md`)
```
Convert the table in this region to Markdown table format.
- Maintain row and column alignment
- Preserve all data and values
- Handle merged cells
- Preserve headers and units
```

### Figure Mode (`prompts/figure.md`)
```
Analyze the chart or image in this region:
1. Chart type (bar, line, pie, flowchart, etc.)
2. Titles and axis labels
3. Data trends and key observations
4. Important values and anomalies
Describe in Markdown format.
```

## Using in OpenClaw

```python
import subprocess
from pathlib import Path

# Process PDF (auto mode)
subprocess.run([
    "python", "skills/pdf-ocr-tool/ocr_tool.py",
    "--input", "/path/to/document.pdf",
    "--output", "/tmp/result.md",
    "--mode", "auto"
])

# Read result
with open("/tmp/result.md", "r") as f:
    markdown_content = f.read()

# Process single image (table mode)
subprocess.run([
    "python", "skills/pdf-ocr-tool/ocr_tool.py",
    "--input", "/path/to/table.png",
    "--output", "/tmp/table.md",
    "--mode", "table"
])

# Mixed mode for complex PDF
subprocess.run([
    "python", "skills/pdf-ocr-tool/ocr_tool.py",
    "--input", "/path/to/mixed.pdf",
    "--output", "/tmp/mixed.md",
    "--granularity", "region",  # Split into regions
    "--save-images"  # Save figure images
])
```

## Troubleshooting

### Model Not Installed
```bash
ollama pull glm-ocr:q8_0
```

### Service Not Running
```bash
ollama serve
```

### Missing pdftoppm
```bash
sudo apt install poppler-utils  # Debian/Ubuntu
brew install poppler            # macOS
```

### Poor OCR Results
- Try different modes: `--mode text` or `--mode mixed`
- Use custom prompts: `--prompt "your prompt here"`
- Check image quality (resolution, clarity)
- Try mixed mode: `--granularity region`

### Dependency Issues
```bash
cd skills/pdf-ocr-tool
source .venv/bin/activate
uv sync  # Reinstall all dependencies
```

## Related Resources

- [Ollama API Documentation](https://docs.ollama.com/api/generate)
- [GLM-OCR Model Page](https://ollama.com/library/glm-ocr)
- [poppler-utils](https://poppler.freedesktop.org/)
- [uv Package Manager](https://github.com/astral-sh/uv)

## Version History

- **v1.2.0** - English prompts, install-deps.sh, fixed .gitignore
- **v1.1.0** - Added mixed mode, region splitting, pyproject.toml
- **v1.0.0** - Initial version with basic OCR functionality

## Credits

This tool is developed and maintained by the OpenClaw community.

## License

MIT License

「办公效率」分类下的热门技能

数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。