Skip to content

staruhub/ClaudeSkills / skills/Geek-skills-mineru-pdf-parser

mineru-pdf-parser

Verified

用 MinerU 将复杂PDF文档转换为LLM友好的Markdown/JSON格式。适用于:(1) PDF转Markdown/JSON,(2) 提取PDF中的文本、表格、公式、图像,(3) 解析学术论文、技术文档、商业报告,(4) 为RAG应用准备文档数据,(5) 批量处理PDF。触发关键词:"PDF解析"、"PDF转Markdown"、"提取PDF表格/公式"、"MinerU"、"parse PDF"等。不用于:PDF的阅读/填表/签名/拆分合并(用宿主pdf工具)、Word/PPT等非PDF格式解析、只需读几页内容的场景(直接读即可,不必转换)。

FileKindSize
SKILL.mdskill md3.8 KB
references/api_reference.mdmarkdown3.0 KB
references/best_practices.mdmarkdown5.5 KB
references/output_formats.mdmarkdown3.1 KB
scripts/mineru_parse.pyscript8.2 KB

references/api_reference.md

View on GitHub
# MinerU API Reference

## 命令行工具

### 基本用法

```bash
mineru -p <input_path> -o <output_path> [options]
```

### 参数说明

| 参数 | 说明 | 默认值 |
|------|------|--------|
| `-p, --path` | 输入PDF文件或目录路径 | 必需 |
| `-o, --output` | 输出目录路径 | 必需 |
| `--backend` | 解析后端: `pipeline`, `vlm`, `hybrid` | `hybrid` |
| `--lang` | OCR语言代码 | 自动检测 |
| `--source` | 模型源: `huggingface`, `modelscope` | `huggingface` |

### 示例

```bash
# 基本解析
mineru -p document.pdf -o output/

# 使用VLM高精度模式
mineru -p paper.pdf -o output/ --backend vlm

# 指定中文OCR
mineru -p chinese_doc.pdf -o output/ --lang ch

# 批量处理目录
mineru -p ./pdfs/ -o ./output/
```

## Python API

### MinerU 类

```python
from mineru import MinerU

# 初始化
mineru = MinerU(
    backend="hybrid",    # 解析后端
    device="cuda",       # 设备: cuda/cpu/mps
    lang="auto"          # OCR语言
)

# 解析PDF
result = mineru.parse(
    path="document.pdf", # PDF路径
    start_page=0,        # 起始页(可选)
    end_page=None        # 结束页(可选)
)
```

### ParseResult 对象

```python
# 获取Markdown
markdown = result.to_markdown()

# 获取JSON
json_data = result.to_json()

# 获取章节列表
sections = result.get_sections()

# 获取表格
tables = result.get_tables()

# 获取公式
formulas = result.get_formulas()

# 获取图像
images = result.get_images()

# 保存结果
result.save(output_dir="output/")
```

### 批量处理

```python
from mineru import MinerU
from pathlib import Path

mineru = MinerU(backend="hybrid")

# 批量解析
pdf_files = list(Path("pdfs/").glob("*.pdf"))
results = mineru.batch_parse(pdf_files, workers=4)

for result in results:
    result.save(f"output/{result.filename}/")
```

## FastAPI 服务

### 启动服务

```bash
mineru-api --host 0.0.0.0 --port 8000
```

### API 端点

#### POST /parse
解析PDF文件

**请求体:**
```json
{
  "file": "base64编码的PDF内容",
  "backend": "hybrid",
  "output_format": "markdown"
}
```

**响应:**
```json
{
  "status": "success",
  "markdown": "# 文档标题\n...",
  "metadata": {
    "pages": 10,
    "tables": 3,
    "formulas": 15
  }
}
```

#### GET /health
健康检查

**响应:**
```json
{
  "status": "ok",
  "version": "2.7.0"
}
```

### 访问API文档

启动服务后访问 `http://127.0.0.1:8000/docs` 查看完整Swagger文档。

## Gradio WebUI

```bash
mineru-webui --port 7860
```

访问 `http://127.0.0.1:7860` 使用图形界面。

## 配置文件

配置文件位于 `~/.mineru.json`:

```json
{
  "device-mode": "cuda",
  "models-dir": "/path/to/models",
  "formula-delimiter": "$",
  "llm-aided-config": {
    "api_key": "your_api_key",
    "base_url": "https://api.openai.com/v1",
    "model": "gpt-4",
    "enable": false
  }
}
```

## 错误处理

```python
from mineru import MinerU, MinerUError

mineru = MinerU()

try:
    result = mineru.parse("document.pdf")
except MinerUError as e:
    print(f"解析错误: {e}")
```
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall