瀏覽代碼

feat(document-skills): 新增 OCR 识别功能并扩展文档处理技能

- 集成 OCRmyPDF 核心 OCR 功能,支持 100+ 种语言
- 添加 OCRmyPDF 图像处理技能,支持纠偏、旋转、去噪等
- 实现 OCRmyPDF 优化与输出控制,支持压缩级别和 PDF/A
- 增加 OCRmyPDF 批量处理与自动化功能
- 集成 OCRmyPDF Python API 与插件系统
- 更新文档处理技能描述,技能数量从 10 个扩展到 15 个
- 更新总技能数从 171 个增加到 176 个
- 在 README 中添加 OCR 识别相关文档说明
wandl-6A72h 7 月之前
父節點
當前提交
b5f3949872

+ 7 - 2
.claude-plugin/marketplace.json

@@ -5,7 +5,7 @@
     "email": "partmeai@gmail.com"
   },
   "metadata": {
-    "description": "PartMeAI 免费技能市场 - 面向期望成为全栈技能人才的群体,提供按技能种类组织的实用工具技能集合。严格遵循 Agent Skills 规范,提供 169 个技能集合,按技能种类组织为 12 个插件类别,覆盖软件开发全生命周期。在 AI 时代,赋能全栈独立开发者,通过 AI 助手掌握专业技能,实现\"一个人 = 一个公司\"的愿景。",
+    "description": "PartMeAI 免费技能市场 - 面向期望成为全栈技能人才的群体,提供按技能种类组织的实用工具技能集合。严格遵循 Agent Skills 规范,提供 174 个技能集合,按技能种类组织为 12 个插件类别,覆盖软件开发全生命周期。在 AI 时代,赋能全栈独立开发者,通过 AI 助手掌握专业技能,实现\"一个人 = 一个公司\"的愿景。",
     "version": "0.0.1"
   },
   "plugins": [
@@ -141,7 +141,7 @@
     },
     {
       "name": "document-skills",
-      "description": "文档处理技能集合(10个技能):包含 Word(docx)、PowerPoint(pptx)、Excel(xlsx)、PDF 等办公文档的创建、编辑和处理;文档协作(多人协作编辑);API 文档生成器;Draw.io 流程图绘制;ProcessOn 思维导图绘制;Mermaid 图表绘制;PlantUML 架构图绘制。帮助 AI 助手掌握文档处理、图表绘制、文档协作等办公自动化技能。",
+      "description": "文档处理技能集合(15个技能):包含 Word(docx)、PowerPoint(pptx)、Excel(xlsx)、PDF 等办公文档的创建、编辑和处理;OCRmyPDF 扫描件 OCR 识别(核心 OCR、图像处理、优化压缩、批量处理、Python API 及插件);文档协作(多人协作编辑);API 文档生成器;Draw.io 流程图绘制;ProcessOn 思维导图绘制;Mermaid 图表绘制;PlantUML 架构图绘制。帮助 AI 助手掌握文档处理、OCR 识别、图表绘制、文档协作等办公自动化技能。",
       "source": "./",
       "strict": false,
       "skills": [
@@ -149,6 +149,11 @@
         "./skills/pptx",
         "./skills/pdf",
         "./skills/xlsx",
+        "./skills/ocrmypdf",
+        "./skills/ocrmypdf-image",
+        "./skills/ocrmypdf-optimize",
+        "./skills/ocrmypdf-batch",
+        "./skills/ocrmypdf-api",
         "./skills/doc-coauthoring",
         "./skills/api-doc-generator",
         "./skills/drawio-flowchart",

+ 19 - 11
README.md

@@ -6,14 +6,14 @@
 
 ![Version](https://img.shields.io/badge/Version-0.0.1-red)
 ![License](https://img.shields.io/badge/License-Apache%202.0-green)
-![Skills](https://img.shields.io/badge/Skills-171-orange)
+![Skills](https://img.shields.io/badge/Skills-176-orange)
 ![Plugins](https://img.shields.io/badge/Plugins-12-brightgreen)
 
 </div>
 
 ## 📖 简介
 
-**Full-Stack-Skills(Alpha)** 是一个开源的 Agent Skills 集合,严格遵循 Agent Skills 规范,提供 **171 个技能集合**,按**技能种类**组织为 **12 个插件类别**,覆盖软件开发全生命周期。在 AI 时代,它赋能全栈独立开发者,通过 AI 助手掌握专业技能,实现**"一个人 = 一个公司"**的愿景,让独立开发者能够独立完成从产品设计、开发、测试到部署运维的全流程工作。
+**Full-Stack-Skills(Alpha)** 是一个开源的 Agent Skills 集合,严格遵循 Agent Skills 规范,提供 **176 个技能集合**,按**技能种类**组织为 **12 个插件类别**,覆盖软件开发全生命周期。在 AI 时代,它赋能全栈独立开发者,通过 AI 助手掌握专业技能,实现**"一个人 = 一个公司"**的愿景,让独立开发者能够独立完成从产品设计、开发、测试到部署运维的全流程工作。
 
 > **⚠️ 注意:** 当前项目处于 Alpha 阶段,尚未经过严格测试,还在自测中。欢迎反馈问题和建议。
 
@@ -54,7 +54,7 @@ Skills 是由说明、脚本和资源组成的文件夹,Claude 会按需动态
 - **持续更新**:社区驱动,持续添加新技能和改进现有技能
 
 #### 2. 全栈覆盖
-- **171 个技能集合**:覆盖前端、后端、移动端、数据库、测试、DevOps、云平台、设计等全栈开发领域
+- **176 个技能集合**:覆盖前端、后端、移动端、数据库、测试、DevOps、云平台、设计等全栈开发领域
 - **12 个插件类别**:按技能种类组织,而非按岗位划分,便于灵活组合使用
 - **跨平台支持**:支持 Claude Code、Claude.ai、Claude API 及其他 AI 平台
 
@@ -74,7 +74,7 @@ Skills 是由说明、脚本和资源组成的文件夹,Claude 会按需动态
 
 - **开发类**:前端开发(Vue、React、Angular)、后端开发(Spring、Node.js、Python、Go)、移动端开发(UniApp、React Native、Flutter)、开发工具
 - **设计类**:UI设计工具、AI设计工具、原型工具
-- **文档类**:文档生成、文档处理、图表绘制(Mermaid、PlantUML)
+- **文档类**:文档生成、文档处理、OCR 识别(OCRmyPDF)、图表绘制(Mermaid、PlantUML)
 - **架构类**:DDD、微服务、事件驱动、六边形架构、整洁架构、COLA
 - **测试类**:单元测试、集成测试、E2E测试、移动端测试
 - **运维类**:CI/CD、容器化、IaC
@@ -103,7 +103,7 @@ Skills 是由说明、脚本和资源组成的文件夹,Claude 会按需动态
 - **插件化**:12 个插件类别,可按需安装
 
 #### **全栈覆盖**
-- **171 个技能**:覆盖前端、后端、移动端、数据库、测试、DevOps、云平台、设计等全栈开发领域
+- **176 个技能**:覆盖前端、后端、移动端、数据库、测试、DevOps、云平台、设计等全栈开发领域
 - **跨平台支持**:支持 Claude Code、Claude.ai、Claude API 及其他 AI 平台
 - **持续更新**:社区驱动,持续添加新技能和改进现有技能
 
@@ -138,7 +138,7 @@ full-stack-skills/
 │   │   └── LICENSE.txt           # 许可证
 │   ├── vue3/
 │   ├── react/
-│   └── ...                       # 171 个技能
+│   └── ...                       # 176 个技能
 ├── adapters/                     # 跨平台适配器
 │   ├── cursor/                   # Cursor 适配器
 │   ├── trae/                     # Trae 适配器
@@ -155,7 +155,7 @@ full-stack-skills/
 | development-skills | 76 | 全栈开发技能集合 |
 | development-skills-utils | 12 | 开发工具技能集合 |
 | design-skills | 16 | 设计技能集合 |
-| document-skills | 10 | 文档处理技能集合 |
+| document-skills | 15 | 文档处理技能集合 |
 | architecture-skills | 7 | 架构技能集合 |
 | testing-skills | 9 | 测试技能集合 |
 | devops-skills | 9 | 运维技能集合 |
@@ -284,6 +284,7 @@ python convert_all.py ../skills ../adapters-output
 
 ### 4. 文档处理
 - **办公文档**:支持 Word、PowerPoint、Excel、PDF 等文档处理
+- **OCR 识别**:支持 OCRmyPDF 扫描件 OCR(100+ 语言、图像处理、优化压缩、批量处理、Python API、多引擎插件)
 - **图表绘制**:支持 Mermaid、PlantUML、Draw.io 等图表绘制
 - **文档协作**:支持多人协作编辑
 
@@ -294,7 +295,7 @@ python convert_all.py ../skills ../adapters-output
 
 ## 可用插件和技能
 
-本仓库的技能按**技能种类**分为 **12 个插件类别**,共包含 **171 个技能**。
+本仓库的技能按**技能种类**分为 **12 个插件类别**,共包含 **176 个技能**。
 
 ---
 
@@ -383,9 +384,9 @@ python convert_all.py ../skills ../adapters-output
 
 **安装命令:** `/plugin install document-skills@full-stack-skills`
 
-**技能数量:** 10 个技能
+**技能数量:** 15 个技能
 
-**描述:** 文档处理技能集合,包含办公文档的创建、编辑和处理;文档协作;API 文档生成;流程图和思维导图绘制;Mermaid 和 PlantUML 图表绘制等。帮助 AI 助手掌握文档处理、图表绘制、文档协作等办公自动化技能。
+**描述:** 文档处理技能集合,包含办公文档的创建、编辑和处理;OCRmyPDF 扫描件 OCR 识别(核心 OCR、图像处理、优化压缩、批量处理、Python API 及插件);文档协作;API 文档生成;流程图和思维导图绘制;Mermaid 和 PlantUML 图表绘制等。帮助 AI 助手掌握文档处理、OCR 识别、图表绘制、文档协作等办公自动化技能。
 
 #### 办公文档处理
 - `docx` - Word 文档处理
@@ -393,6 +394,13 @@ python convert_all.py ../skills ../adapters-output
 - `pdf` - PDF 文档处理
 - `xlsx` - Excel 电子表格处理
 
+#### OCR 识别(OCRmyPDF)
+- `ocrmypdf` - OCRmyPDF 核心 OCR(安装、基本 OCR、多语言、OCR 模式)
+- `ocrmypdf-image` - 图像处理(纠偏、旋转、去噪、清理扫描件)
+- `ocrmypdf-optimize` - 优化与输出(压缩级别、PDF/A、JBIG2 编码)
+- `ocrmypdf-batch` - 批量处理与自动化(Shell 脚本、Docker、CI/CD)
+- `ocrmypdf-api` - Python API 与插件(编程调用、EasyOCR、PaddleOCR)
+
 #### 文档协作与生成
 - `doc-coauthoring` - 文档协作(多人协作编辑)
 - `api-doc-generator` - API 文档生成器
@@ -574,7 +582,7 @@ python convert_all.py ../skills ../adapters-output
 | 项目 | 当前版本          |
 |---|---------------|
 | full-stack-skills | 0.0.1 (Alpha) |
-| 技能总数 | 171           |
+| 技能总数 | 176           |
 | 插件类别 | 12            |
 | Agent Skills 规范 | 最新版本          |
 

+ 226 - 0
skills/ocrmypdf-api/SKILL.md

@@ -0,0 +1,226 @@
+---
+name: ocrmypdf-api
+description: OCRmyPDF Python API and plugin skill — use OCRmyPDF programmatically from Python, integrate with applications, and extend with plugins (EasyOCR, PaddleOCR, AppleOCR). Use when the user needs to call OCRmyPDF from Python code, build OCR pipelines, or use alternative OCR engines.
+---
+
+# OCRmyPDF — Python API & Plugins Guide
+
+## Overview
+
+OCRmyPDF provides a Python API for programmatic use and a plugin interface for extending or replacing OCR engines. This skill covers the Python API, integration patterns, and the plugin ecosystem.
+
+For CLI usage, see the **ocrmypdf** skill. For batch scripting, see **ocrmypdf-batch**.
+
+## Python API
+
+### Basic usage
+
+```python
+import ocrmypdf
+
+# Basic OCR
+exit_code = ocrmypdf.ocr('input.pdf', 'output.pdf')
+
+# With options
+exit_code = ocrmypdf.ocr(
+    'input.pdf',
+    'output.pdf',
+    language='eng+fra',
+    deskew=True,
+    rotate_pages=True,
+    skip_text=True,
+    optimize=2,
+    jobs=4,
+)
+```
+
+### Return codes
+
+```python
+import ocrmypdf
+
+result = ocrmypdf.ocr('input.pdf', 'output.pdf')
+
+if result == ocrmypdf.ExitCode.ok:
+    print("OCR completed successfully")
+elif result == ocrmypdf.ExitCode.already_done_ocr:
+    print("PDF already has OCR text")
+elif result == ocrmypdf.ExitCode.input_file:
+    print("Input file issue")
+else:
+    print(f"Error: {result}")
+```
+
+### Common API parameters
+
+| Parameter | Type | Description |
+|-----------|------|-------------|
+| `language` | str | Tesseract language(s), e.g. `'eng+fra'` |
+| `deskew` | bool | Straighten crooked pages |
+| `rotate_pages` | bool | Auto-rotate pages |
+| `skip_text` | bool | Skip pages that already have text |
+| `force_ocr` | bool | Force OCR on all pages |
+| `redo_ocr` | bool | Replace existing OCR |
+| `optimize` | int | Optimization level (0-3) |
+| `output_type` | str | `'pdfa'`, `'pdf'`, `'auto'`, `'none'` |
+| `jobs` | int | Number of parallel workers |
+| `sidecar` | str | Path for sidecar text file |
+| `image_dpi` | int | DPI for image inputs |
+| `clean` | bool | Clean pages with unpaper (OCR only) |
+| `clean_final` | bool | Clean pages and use in output |
+| `remove_background` | bool | Remove noisy backgrounds |
+| `oversample` | int | Oversample DPI for low-res images |
+| `pages` | str | Page range, e.g. `'1,3,5-10'` |
+| `title` | str | Output PDF title |
+| `author` | str | Output PDF author |
+
+### Integration example: Flask web service
+
+```python
+from flask import Flask, request, send_file
+import ocrmypdf
+import tempfile
+import os
+
+app = Flask(__name__)
+
+@app.route('/ocr', methods=['POST'])
+def ocr_endpoint():
+    """OCR a PDF via HTTP POST."""
+    if 'file' not in request.files:
+        return {'error': 'No file uploaded'}, 400
+
+    uploaded = request.files['file']
+    with tempfile.NamedTemporaryFile(suffix='.pdf', delete=False) as inp:
+        uploaded.save(inp.name)
+        out_path = inp.name.replace('.pdf', '_ocr.pdf')
+
+    try:
+        result = ocrmypdf.ocr(
+            inp.name, out_path,
+            language='eng',
+            skip_text=True,
+            optimize=2,
+        )
+        if result == ocrmypdf.ExitCode.ok:
+            return send_file(out_path, as_attachment=True,
+                             download_name='ocr_output.pdf')
+        return {'error': f'OCR failed: {result}'}, 500
+    finally:
+        os.unlink(inp.name)
+        if os.path.exists(out_path):
+            os.unlink(out_path)
+
+if __name__ == '__main__':
+    app.run(port=5000)
+```
+
+### Streamlit web UI
+
+OCRmyPDF provides an optional Streamlit-based web UI:
+
+```bash
+pip install ocrmypdf[webservice]
+# See OCRmyPDF docs for launching the web service
+```
+
+## Plugin Ecosystem
+
+OCRmyPDF's plugin interface allows replacing the OCR engine. Available plugins:
+
+### OCRmyPDF-EasyOCR
+
+Replaces Tesseract with [EasyOCR](https://github.com/JaidedAI/EasyOCR) (PyTorch-based). GPU strongly recommended.
+
+```bash
+pip install ocrmypdf-easyocr
+
+# Usage
+ocrmypdf --plugin ocrmypdf_easyocr -l en input.pdf output.pdf
+```
+
+### OCRmyPDF-PaddleOCR
+
+Replaces Tesseract with [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR). Powerful GPU-accelerated engine.
+
+```bash
+pip install ocrmypdf-paddleocr
+
+# Usage
+ocrmypdf --plugin ocrmypdf_paddleocr input.pdf output.pdf
+```
+
+### OCRmyPDF-AppleOCR
+
+Replaces Tesseract with Apple Vision Framework. macOS only.
+
+```bash
+pip install ocrmypdf-appleocr
+
+# Usage
+ocrmypdf --plugin ocrmypdf_appleocr input.pdf output.pdf
+```
+
+### paperless-ngx Integration
+
+[paperless-ngx](https://docs.paperless-ngx.com/) uses OCRmyPDF internally for searchable document management. See paperless-ngx docs for configuration.
+
+## Custom Plugins
+
+Create a custom OCR plugin by implementing the OCRmyPDF plugin interface:
+
+```python
+# my_ocr_plugin.py
+from ocrmypdf import OcrEngine, hookimpl
+
+class MyOcrEngine(OcrEngine):
+    """Custom OCR engine implementation."""
+
+    @staticmethod
+    def version():
+        return "1.0.0"
+
+    @staticmethod
+    def creator_tag(options):
+        return "MyOCR"
+
+    def recognize(self, input_file, output_file, output_text, options):
+        # Implement OCR logic here
+        pass
+
+@hookimpl
+def get_ocr_engine():
+    return MyOcrEngine()
+```
+
+```bash
+# Use custom plugin
+ocrmypdf --plugin my_ocr_plugin input.pdf output.pdf
+```
+
+## Quick Reference
+
+| Task | Code / Command |
+|------|----------------|
+| Python API basic | `ocrmypdf.ocr('in.pdf', 'out.pdf')` |
+| With options | `ocrmypdf.ocr('in.pdf', 'out.pdf', language='eng', deskew=True)` |
+| Check result | `if result == ocrmypdf.ExitCode.ok: ...` |
+| EasyOCR plugin | `ocrmypdf --plugin ocrmypdf_easyocr in.pdf out.pdf` |
+| PaddleOCR plugin | `ocrmypdf --plugin ocrmypdf_paddleocr in.pdf out.pdf` |
+| AppleOCR plugin | `ocrmypdf --plugin ocrmypdf_appleocr in.pdf out.pdf` |
+
+## Troubleshooting
+
+- **Import error**: Ensure `pip install ocrmypdf` in your Python environment.
+- **Plugin not found**: Check plugin is installed (`pip install ocrmypdf-easyocr`).
+- **GPU not used (EasyOCR/PaddleOCR)**: Ensure CUDA/GPU drivers are installed.
+- **Memory issues**: Use `jobs=1` for large files; process in batches.
+
+## References
+
+- [OCRmyPDF API Reference](https://ocrmypdf.readthedocs.io/en/latest/api.html)
+- [OCRmyPDF Plugin Interface](https://ocrmypdf.readthedocs.io/en/latest/plugins.html)
+- [OCRmyPDF-EasyOCR](https://github.com/ocrmypdf/OCRmyPDF-EasyOCR)
+- [OCRmyPDF-PaddleOCR](https://github.com/clefru/ocrmypdf-paddleocr)
+- [OCRmyPDF-AppleOCR](https://github.com/mkyt/ocrmypdf-AppleOCR)
+- [paperless-ngx](https://docs.paperless-ngx.com/)

+ 203 - 0
skills/ocrmypdf-batch/SKILL.md

@@ -0,0 +1,203 @@
+---
+name: ocrmypdf-batch
+description: OCRmyPDF batch processing skill — process multiple PDFs in bulk, use Docker containers, automate with shell scripts, and set up watch folders. Use when the user needs to OCR many PDFs at once, automate OCR in CI/CD, or run OCRmyPDF in Docker.
+---
+
+# OCRmyPDF — Batch Processing, Docker & Automation Guide
+
+## Overview
+
+This skill covers batch processing multiple PDFs, Docker deployment, shell scripting automation, and watch folder setups with OCRmyPDF.
+
+For core OCR operations, see the **ocrmypdf** skill. For image processing, see **ocrmypdf-image**. For Python API, see **ocrmypdf-api**.
+
+## Batch Processing with Shell
+
+### Process all PDFs in a directory
+
+```bash
+#!/bin/bash
+# OCR all PDFs in a directory
+INPUT_DIR="./scans"
+OUTPUT_DIR="./ocr-output"
+mkdir -p "$OUTPUT_DIR"
+
+for pdf in "$INPUT_DIR"/*.pdf; do
+    filename=$(basename "$pdf")
+    echo "Processing: $filename"
+    ocrmypdf --skip-text -l eng "$pdf" "$OUTPUT_DIR/$filename"
+done
+echo "Done!"
+```
+
+### Parallel batch processing with GNU parallel
+
+```bash
+# Process all PDFs in parallel using GNU parallel
+find ./scans -name "*.pdf" | parallel -j4 \
+    ocrmypdf --skip-text -l eng {} ./output/{/}
+```
+
+### Recursive directory processing
+
+```bash
+#!/bin/bash
+# Recursively OCR all PDFs, preserving directory structure
+INPUT_DIR="./documents"
+OUTPUT_DIR="./searchable"
+
+find "$INPUT_DIR" -name "*.pdf" -type f | while read -r pdf; do
+    rel_path="${pdf#$INPUT_DIR/}"
+    out_path="$OUTPUT_DIR/$rel_path"
+    mkdir -p "$(dirname "$out_path")"
+    echo "OCR: $rel_path"
+    ocrmypdf --skip-text -l eng "$pdf" "$out_path" 2>&1 || echo "FAILED: $rel_path"
+done
+```
+
+### In-place OCR (overwrite originals on success)
+
+```bash
+#!/bin/bash
+# OCR files in place — only overwrites on success
+for pdf in ./documents/*.pdf; do
+    echo "Processing: $pdf"
+    ocrmypdf --skip-text "$pdf" "$pdf"
+done
+```
+
+## Docker
+
+### Official Docker images
+
+Available for x64 and ARM:
+
+```bash
+# Pull the latest image
+docker pull jbarlow83/ocrmypdf
+
+# Basic usage
+docker run --rm -v "$(pwd):/data" jbarlow83/ocrmypdf \
+    /data/input.pdf /data/output.pdf
+
+# With language and options
+docker run --rm -v "$(pwd):/data" jbarlow83/ocrmypdf \
+    -l eng+fra --deskew /data/input.pdf /data/output.pdf
+```
+
+### Batch processing with Docker
+
+```bash
+#!/bin/bash
+# Batch OCR using Docker
+INPUT_DIR="$(pwd)/scans"
+OUTPUT_DIR="$(pwd)/output"
+mkdir -p "$OUTPUT_DIR"
+
+for pdf in "$INPUT_DIR"/*.pdf; do
+    filename=$(basename "$pdf")
+    echo "Processing: $filename"
+    docker run --rm \
+        -v "$INPUT_DIR:/input:ro" \
+        -v "$OUTPUT_DIR:/output" \
+        jbarlow83/ocrmypdf \
+        --skip-text -l eng \
+        "/input/$filename" "/output/$filename"
+done
+```
+
+### Docker Compose (watch folder)
+
+```yaml
+# docker-compose.yml
+version: '3'
+services:
+  ocrmypdf-watcher:
+    image: jbarlow83/ocrmypdf
+    volumes:
+      - ./inbox:/inbox
+      - ./outbox:/outbox
+    entrypoint: >
+      sh -c 'while true; do
+        for f in /inbox/*.pdf; do
+          [ -f "$$f" ] || continue;
+          ocrmypdf --skip-text "$$f" "/outbox/$$(basename $$f)" &&
+          rm "$$f";
+        done;
+        sleep 10;
+      done'
+```
+
+## Watch Folder with Watcher Extension
+
+OCRmyPDF provides an optional watcher service:
+
+```bash
+# Install watcher extension
+pip install ocrmypdf[watcher]
+
+# Run the watcher (monitors input folder, outputs to output folder)
+# See OCRmyPDF docs for watcher configuration
+```
+
+## CI/CD Integration
+
+### GitHub Actions example
+
+```yaml
+name: OCR PDFs
+on: push
+jobs:
+  ocr:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+      - name: Install OCRmyPDF
+        run: |
+          sudo apt-get update
+          sudo apt-get install -y ocrmypdf tesseract-ocr-eng
+      - name: OCR all PDFs
+        run: |
+          mkdir -p output
+          for pdf in docs/*.pdf; do
+            ocrmypdf --skip-text "$pdf" "output/$(basename "$pdf")"
+          done
+      - uses: actions/upload-artifact@v4
+        with:
+          name: ocr-pdfs
+          path: output/
+```
+
+## Convert Multiple Images to Searchable PDF
+
+```bash
+# Use img2pdf to combine images, then pipe to ocrmypdf
+pip install img2pdf
+
+# Combine and OCR
+img2pdf scan_*.jpg | ocrmypdf - output.pdf
+
+# Or one image at a time
+ocrmypdf --image-dpi 300 scan.jpg output.pdf
+```
+
+## Quick Reference
+
+| Task | Command |
+|------|---------|
+| Batch OCR directory | `for f in *.pdf; do ocrmypdf "$f" "out/$f"; done` |
+| Parallel batch | `find . -name "*.pdf" \| parallel ocrmypdf {} out/{/}` |
+| Docker single file | `docker run --rm -v "$(pwd):/data" jbarlow83/ocrmypdf /data/in.pdf /data/out.pdf` |
+| In-place OCR | `ocrmypdf myfile.pdf myfile.pdf` |
+| Images to PDF | `img2pdf *.jpg \| ocrmypdf - output.pdf` |
+
+## Troubleshooting
+
+- **Docker permission errors**: Ensure volume mounts are correct; use `--user $(id -u):$(id -g)` if needed.
+- **Batch script fails on one file**: Add error handling (`|| echo "FAILED"`) to continue processing.
+- **Memory issues on large batches**: Process files sequentially with `--jobs 1`, or limit parallel workers.
+
+## References
+
+- [OCRmyPDF Docker](https://ocrmypdf.readthedocs.io/en/latest/docker.html)
+- [OCRmyPDF Cookbook: Batch Processing](https://ocrmypdf.readthedocs.io/en/latest/cookbook.html)

+ 171 - 0
skills/ocrmypdf-image/SKILL.md

@@ -0,0 +1,171 @@
+---
+name: ocrmypdf-image
+description: OCRmyPDF image processing skill — deskew crooked pages, auto-rotate, remove backgrounds, and clean scanned images before OCR. Use when the user needs to fix page rotation, straighten crooked scans, or clean up noisy scanned PDFs.
+---
+
+# OCRmyPDF — Image Processing Guide
+
+## Overview
+
+OCRmyPDF can perform image processing on each page of a PDF before OCR. These operations fix common scanning issues: crooked pages, wrong orientation, noisy backgrounds, and dirty scans. Processing is applied per-page.
+
+For core OCR operations (install, languages, modes), see the **ocrmypdf** skill. For optimization, see **ocrmypdf-optimize**.
+
+**Important**: Image processing will rasterize PDF pages as images, potentially losing vector content quality. Always review output files.
+
+## Image Processing Options
+
+### Rotate Pages (`--rotate-pages`)
+
+Automatically detects and corrects page orientation (0/90/180/270 degrees).
+
+```bash
+# Auto-rotate misoriented pages
+ocrmypdf --rotate-pages input.pdf output.pdf
+
+# Adjust rotation aggressiveness (default: 14.0, lower = more aggressive)
+ocrmypdf --rotate-pages --rotate-pages-threshold 2.0 input.pdf output.pdf
+```
+
+**Tip**: Use `-v1` to see confidence levels per page and tune the threshold.
+
+### Deskew (`--deskew`)
+
+Straightens pages that were scanned at a slight angle (crooked scans).
+
+```bash
+# Straighten crooked pages
+ocrmypdf --deskew input.pdf output.pdf
+```
+
+**Note**: `--deskew` fixes "slightly off horizontal" pages. For pages at the wrong cardinal angle (90/180/270), use `--rotate-pages`.
+
+### Remove Background (`--remove-background`)
+
+Attempts to detect and remove noisy backgrounds from grayscale/color images. Monochrome images are ignored.
+
+```bash
+# Remove noisy background
+ocrmypdf --remove-background input.pdf output.pdf
+```
+
+**Warning**: Do not use on documents with color photos — it may remove them.
+
+### Clean (`--clean`)
+
+Uses [unpaper](https://www.flameeyes.eu/projects/unpaper) to clean pages before OCR, but does **not** alter the final output PDF. Improves OCR accuracy without changing appearance.
+
+```bash
+# Clean for better OCR (output unchanged)
+ocrmypdf --clean input.pdf output.pdf
+```
+
+**Requires**: unpaper installed on the system.
+
+### Clean Final (`--clean-final`)
+
+Like `--clean`, but inserts the cleaned page into the final output. Review each page — unpaper may remove important content.
+
+```bash
+# Clean and use cleaned version in output
+ocrmypdf --clean-final input.pdf output.pdf
+```
+
+**Warning**: May leave visual artifacts. Always review output.
+
+### Oversample (`--oversample DPI`)
+
+Resample images to higher resolution before OCR, which can improve accuracy for low-DPI scans.
+
+```bash
+# Oversample to 400 DPI
+ocrmypdf --oversample 400 input.pdf output.pdf
+```
+
+## Combining Options
+
+Image processing options can be combined freely. The order of command-line flags does not matter — OCRmyPDF always applies them in this fixed order:
+
+1. Rotate
+2. Remove background
+3. Deskew
+4. Clean
+
+```bash
+# Full processing pipeline
+ocrmypdf --rotate-pages --deskew --clean input.pdf output.pdf
+
+# Deskew + clean final (aggressive cleanup)
+ocrmypdf --deskew --clean-final input.pdf output.pdf
+
+# Everything: rotate, remove background, deskew, clean
+ocrmypdf --rotate-pages --remove-background --deskew --clean input.pdf output.pdf
+```
+
+## Processing Without OCR
+
+Apply image processing without performing OCR:
+
+```bash
+# Deskew and convert to PDF/A, no OCR
+ocrmypdf --ocr-engine none --deskew --output-type pdfa input.pdf output.pdf
+```
+
+## Rasterizer Selection (v17+)
+
+Choose the PDF rasterization engine:
+
+```bash
+# Auto (default) — prefers pypdfium2 when available
+ocrmypdf --rasterizer auto input.pdf output.pdf
+
+# Explicitly use pypdfium2 (faster)
+ocrmypdf --rasterizer pypdfium input.pdf output.pdf
+
+# Explicitly use Ghostscript
+ocrmypdf --rasterizer ghostscript input.pdf output.pdf
+```
+
+## Quick Reference
+
+| Option | What it does | Notes |
+|--------|-------------|-------|
+| `--rotate-pages` | Fix page orientation (90/180/270) | Use threshold to tune |
+| `--deskew` | Straighten slightly crooked pages | For small angles |
+| `--remove-background` | Remove noisy backgrounds | Not for photos |
+| `--clean` | Clean pages for OCR only | Output unchanged |
+| `--clean-final` | Clean pages, use in output | Review output! |
+| `--oversample DPI` | Upscale images before OCR | Improves low-DPI scans |
+| `--rasterizer auto/pypdfium/ghostscript` | Choose rasterizer | v17+ |
+
+## Common Recipes
+
+### Fix a crooked batch scan
+
+```bash
+ocrmypdf --deskew --rotate-pages input.pdf output.pdf
+```
+
+### Clean a noisy old document
+
+```bash
+ocrmypdf --deskew --clean --remove-background input.pdf output.pdf
+```
+
+### Maximum preprocessing
+
+```bash
+ocrmypdf --rotate-pages --deskew --clean-final --oversample 400 input.pdf output.pdf
+```
+
+## Troubleshooting
+
+- **`--clean` fails**: Install unpaper (`apt install unpaper` or equivalent).
+- **`--remove-background` removes photos**: Only use on text-only documents; skip for documents with images.
+- **`--clean-final` artifacts**: Review output; try `--clean` instead (does not alter output).
+- **Low OCR quality after processing**: Try `--oversample 300` or `--oversample 400`.
+
+## References
+
+- [OCRmyPDF Cookbook: Image Processing](https://ocrmypdf.readthedocs.io/en/latest/cookbook.html#image-processing)
+- [unpaper](https://www.flameeyes.eu/projects/unpaper)

+ 134 - 0
skills/ocrmypdf-optimize/SKILL.md

@@ -0,0 +1,134 @@
+---
+name: ocrmypdf-optimize
+description: OCRmyPDF optimization skill — control PDF/A output, optimization levels, JBIG2 compression, image quality, and rasterizer selection. Use when the user needs to reduce PDF file size, produce archival PDF/A, or fine-tune OCR output quality.
+---
+
+# OCRmyPDF — Optimization & Output Guide
+
+## Overview
+
+OCRmyPDF optimizes PDF images by default after OCR. This guide covers optimization levels, PDF/A output options, JBIG2 encoding, and advanced output control.
+
+For core OCR operations, see the **ocrmypdf** skill. For image processing, see **ocrmypdf-image**.
+
+## Optimization Levels
+
+The `--optimize N` (`-O N`) flag controls optimization intensity (0-3):
+
+| Level | What it does |
+|-------|-------------|
+| `-O 0` | No optimization |
+| `-O 1` | Lossless optimization (default) |
+| `-O 2` | Lossless + lossy PNG quantization (pngquant) |
+| `-O 3` | Aggressive: all of the above maximized |
+
+```bash
+# No optimization (fastest, largest output)
+ocrmypdf --optimize 0 input.pdf output.pdf
+
+# Default lossless optimization
+ocrmypdf input.pdf output.pdf
+
+# Moderate lossy optimization (smaller files)
+ocrmypdf --optimize 2 input.pdf output.pdf
+
+# Maximum compression
+ocrmypdf --optimize 3 input.pdf output.pdf
+```
+
+**Note**: `-O 2` and `-O 3` require **pngquant** installed.
+
+## PDF/A Output
+
+PDF/A is a format for long-term archival. OCRmyPDF produces PDF/A by default.
+
+```bash
+# PDF/A output (default)
+ocrmypdf --output-type pdfa input.pdf output.pdf
+
+# Standard PDF (no PDF/A conversion)
+ocrmypdf --output-type pdf input.pdf output.pdf
+
+# Auto (v17+) — speculative PDF/A with verapdf validation
+ocrmypdf --output-type auto input.pdf output.pdf
+```
+
+### PDF/A Image Compression
+
+```bash
+# JPEG compression for color/grayscale images in PDF/A
+ocrmypdf --output-type pdfa --pdfa-image-compression jpeg input.pdf output.pdf
+
+# Lossless compression (default)
+ocrmypdf --output-type pdfa --pdfa-image-compression lossless input.pdf output.pdf
+```
+
+### PDF/A Without Ghostscript (v17+)
+
+With verapdf installed, OCRmyPDF can produce PDF/A without Ghostscript (faster):
+
+```bash
+ocrmypdf --output-type auto input.pdf output.pdf
+```
+
+## JBIG2 Encoding
+
+JBIG2 significantly reduces monochrome image size. Requires **jbig2enc** installed.
+
+```bash
+# OCRmyPDF automatically uses jbig2enc if available on PATH
+ocrmypdf --optimize 1 input.pdf output.pdf
+```
+
+**Note**: Lossy JBIG2 (`--jbig2-lossy`) was removed in v17.0.0 due to character substitution risks. Only lossless JBIG2 is supported.
+
+### Install jbig2enc
+
+```bash
+# Build from source (not available in most package managers)
+git clone https://github.com/agl/jbig2enc
+cd jbig2enc
+./autogen.sh && ./configure && make && sudo make install
+```
+
+## Optimize Without OCR
+
+```bash
+# Optimize images without performing any OCR
+ocrmypdf --ocr-engine none --optimize 3 --skip-text input.pdf output.pdf
+```
+
+## Digitally Signed PDFs
+
+OCRmyPDF cannot preserve digital signatures. By default it refuses to modify signed PDFs.
+
+```bash
+# Override (invalidates signatures)
+ocrmypdf --invalidate-digital-signatures input.pdf output.pdf
+```
+
+## Quick Reference
+
+| Task | Command |
+|------|---------|
+| No optimization | `ocrmypdf -O 0 input.pdf output.pdf` |
+| Default (lossless) | `ocrmypdf input.pdf output.pdf` |
+| Moderate compression | `ocrmypdf -O 2 input.pdf output.pdf` |
+| Maximum compression | `ocrmypdf -O 3 input.pdf output.pdf` |
+| Standard PDF (no PDF/A) | `ocrmypdf --output-type pdf input.pdf output.pdf` |
+| JPEG in PDF/A | `ocrmypdf --pdfa-image-compression jpeg input.pdf output.pdf` |
+| Optimize only (no OCR) | `ocrmypdf --ocr-engine none -O 3 --skip-text in.pdf out.pdf` |
+| Handle signed PDFs | `ocrmypdf --invalidate-digital-signatures in.pdf out.pdf` |
+
+## Troubleshooting
+
+- **Output larger than input**: This can happen; try `-O 2` or `-O 3`, or `--pdfa-image-compression jpeg`.
+- **pngquant not found**: Install pngquant for `-O 2` / `-O 3`.
+- **"Signed PDF" error**: Use `--invalidate-digital-signatures` (signatures will be lost).
+- **Slow PDF/A**: Install pypdfium2 and verapdf for faster speculative PDF/A (v17+).
+
+## References
+
+- [OCRmyPDF: PDF Optimization](https://ocrmypdf.readthedocs.io/en/latest/optimizer.html)
+- [OCRmyPDF Cookbook](https://ocrmypdf.readthedocs.io/en/latest/cookbook.html#pdf-optimization)
+- [jbig2enc](https://github.com/agl/jbig2enc)

+ 250 - 0
skills/ocrmypdf/SKILL.md

@@ -0,0 +1,250 @@
+---
+name: ocrmypdf
+description: OCRmyPDF core skill — add searchable OCR text layer to scanned PDFs, convert images to searchable PDFs, support 100+ languages via Tesseract. Use when the user needs to OCR a PDF, make a scanned PDF searchable, or extract text from scanned documents.
+---
+
+# OCRmyPDF — Core OCR Guide
+
+## Overview
+
+[OCRmyPDF](https://github.com/ocrmypdf/OCRmyPDF) adds an OCR text layer to scanned PDF files, allowing them to be searched or copy-pasted. It uses Tesseract OCR, supports 100+ languages, produces PDF/A by default, and distributes work across all CPU cores.
+
+For image processing (deskew, rotate, clean), see the **ocrmypdf-image** skill. For optimization and PDF/A options, see **ocrmypdf-optimize**. For batch/Docker/scripting, see **ocrmypdf-batch**. For Python API and plugins, see **ocrmypdf-api**.
+
+## Installation
+
+### One-liner installs (recommended)
+
+| OS | Command |
+|----|---------|
+| **Debian / Ubuntu** | `apt install ocrmypdf` |
+| **Fedora** | `dnf install ocrmypdf tesseract-osd` |
+| **macOS (Homebrew)** | `brew install ocrmypdf` |
+| **macOS (MacPorts)** | `port install ocrmypdf` |
+| **FreeBSD** | `pkg install py-ocrmypdf` |
+| **Snap** | `snap install ocrmypdf` |
+
+### pip install (latest version)
+
+```bash
+# After installing system dependencies (Tesseract, Ghostscript)
+pip install ocrmypdf
+```
+
+### Verify
+
+```bash
+ocrmypdf --version
+ocrmypdf --help
+```
+
+### Requirements
+
+- **Python 3.11+**
+- **Tesseract 4.1.1+** (OCR engine)
+- **Ghostscript 9.54+** or **pypdfium2** (PDF rasterization)
+- Optional: jbig2enc (compression), pngquant (image optimization), unpaper (cleaning)
+
+## Quick Start
+
+```bash
+# Basic OCR — input scanned PDF, output searchable PDF/A
+ocrmypdf input.pdf output.pdf
+
+# OCR an image file directly
+ocrmypdf --image-dpi 300 scan.png output.pdf
+
+# OCR in place (only overwrites on success)
+ocrmypdf myfile.pdf myfile.pdf
+```
+
+## Language Support
+
+OCRmyPDF uses Tesseract language packs. Install them for your OS:
+
+```bash
+# Debian / Ubuntu
+apt-cache search tesseract-ocr          # List all language packs
+apt install tesseract-ocr-chi-sim       # Chinese Simplified
+apt install tesseract-ocr-fra           # French
+
+# macOS (Homebrew)
+brew install tesseract-lang             # All languages
+
+# Fedora
+dnf search tesseract-langpack
+dnf install tesseract-langpack-ita      # Italian
+```
+
+### Using languages
+
+```bash
+# Single language
+ocrmypdf -l fra document.pdf output.pdf
+
+# Multiple languages
+ocrmypdf -l eng+fra bilingual.pdf output.pdf
+
+# Chinese Simplified + English
+ocrmypdf -l chi_sim+eng chinese-doc.pdf output.pdf
+```
+
+**Note**: Use [ISO 639-3 codes](https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html) for language identifiers.
+
+## OCR Modes
+
+### Default mode (skip existing text)
+
+```bash
+# Skip pages that already have text — only OCR pages without text
+ocrmypdf input.pdf output.pdf
+```
+
+### Force OCR (`--force-ocr` or `-m force`)
+
+```bash
+# Rasterize and OCR all pages, even those with existing text
+ocrmypdf --force-ocr input.pdf output.pdf
+# v17+ short form:
+ocrmypdf -m force input.pdf output.pdf
+```
+
+### Redo OCR (`--redo-ocr` or `-m redo`)
+
+```bash
+# Replace existing OCR without rasterizing (preserves quality)
+ocrmypdf --redo-ocr input.pdf output.pdf
+# v17+ short form:
+ocrmypdf -m redo input.pdf output.pdf
+```
+
+### Skip text (`--skip-text` or `-m skip`)
+
+```bash
+# Skip pages with any text, only OCR blank/image pages
+ocrmypdf --skip-text input.pdf output.pdf
+# v17+ short form:
+ocrmypdf -m skip input.pdf output.pdf
+```
+
+### No OCR (image processing only)
+
+```bash
+# Apply image processing / PDF/A conversion without OCR
+ocrmypdf --ocr-engine none input.pdf output.pdf
+```
+
+## Page Selection
+
+```bash
+# OCR only specific pages
+ocrmypdf --pages 1,3,5-10 input.pdf output.pdf
+
+# OCR only the first page, minimal changes elsewhere
+ocrmypdf --pages 1 --output-type pdf --optimize 0 input.pdf output.pdf
+```
+
+## Output Types
+
+```bash
+# PDF/A (default) — for archival
+ocrmypdf --output-type pdfa input.pdf output.pdf
+
+# Standard PDF
+ocrmypdf --output-type pdf input.pdf output.pdf
+
+# Auto (v17+) — speculative PDF/A, falls back to standard PDF
+ocrmypdf --output-type auto input.pdf output.pdf
+
+# No output PDF — only produce sidecar text
+ocrmypdf --output-type none --sidecar text.txt input.pdf -
+```
+
+## Sidecar Text File
+
+```bash
+# Produce a companion text file with OCR text
+ocrmypdf --sidecar output.txt input.pdf output.pdf
+```
+
+## Metadata
+
+```bash
+# Set output PDF metadata
+ocrmypdf --title "My Document" --author "Author Name" --subject "Subject" input.pdf output.pdf
+```
+
+## Parallel Processing
+
+```bash
+# Use 4 CPU cores (default: all available)
+ocrmypdf --jobs 4 input.pdf output.pdf
+
+# Single-threaded
+ocrmypdf --jobs 1 input.pdf output.pdf
+```
+
+## Common Recipes
+
+### Make a scanned PDF searchable
+
+```bash
+ocrmypdf scanned.pdf searchable.pdf
+```
+
+### Convert image to searchable PDF
+
+```bash
+ocrmypdf --image-dpi 300 scan.jpg output.pdf
+```
+
+### OCR a multilingual document
+
+```bash
+ocrmypdf -l eng+deu+fra multilingual.pdf output.pdf
+```
+
+### Re-OCR with newer Tesseract
+
+```bash
+ocrmypdf --redo-ocr old-ocr.pdf updated.pdf
+```
+
+### Strip all text/OCR from a PDF
+
+```bash
+ocrmypdf --ocr-engine none --force-ocr input.pdf stripped.pdf
+```
+
+## Quick Reference
+
+| Task | Command |
+|------|---------|
+| Basic OCR | `ocrmypdf input.pdf output.pdf` |
+| Specify language | `ocrmypdf -l fra input.pdf output.pdf` |
+| Multiple languages | `ocrmypdf -l eng+fra input.pdf output.pdf` |
+| Force re-OCR all pages | `ocrmypdf --force-ocr input.pdf output.pdf` |
+| Replace existing OCR | `ocrmypdf --redo-ocr input.pdf output.pdf` |
+| Skip pages with text | `ocrmypdf --skip-text input.pdf output.pdf` |
+| Specific pages only | `ocrmypdf --pages 1,3,5-10 input.pdf output.pdf` |
+| Output standard PDF | `ocrmypdf --output-type pdf input.pdf output.pdf` |
+| Extract text sidecar | `ocrmypdf --sidecar text.txt input.pdf output.pdf` |
+| Image to PDF | `ocrmypdf --image-dpi 300 image.png output.pdf` |
+| In-place OCR | `ocrmypdf myfile.pdf myfile.pdf` |
+| Set metadata | `ocrmypdf --title "Title" input.pdf output.pdf` |
+| Parallel jobs | `ocrmypdf --jobs 4 input.pdf output.pdf` |
+
+## Troubleshooting
+
+- **"Tesseract not found"**: Install Tesseract and ensure it's on PATH.
+- **Poor OCR quality**: Check language packs (`-l`), try `--deskew` (see ocrmypdf-image), or `--oversample 300`.
+- **"Input file has text"**: Use `--force-ocr`, `--redo-ocr`, or `--skip-text` as appropriate.
+- **Large output files**: See ocrmypdf-optimize for `--optimize` levels and JBIG2.
+- **Signed PDFs**: Use `--invalidate-digital-signatures` to override (signatures will be invalidated).
+
+## References
+
+- [OCRmyPDF Documentation](https://ocrmypdf.readthedocs.io/en/latest/)
+- [OCRmyPDF GitHub](https://github.com/ocrmypdf/OCRmyPDF)
+- [Tesseract Language Packs](https://github.com/tesseract-ocr/tessdata)
+- [OCRmyPDF Cookbook](https://ocrmypdf.readthedocs.io/en/latest/cookbook.html)