Community研究与数据分析github.com

taotaoboom/pdf2md-agent-skill

让 LLM agent 高效读懂任何文档:PDF/Word/PPT/Excel 转 Markdown,PDF 智能分流(文本页 PyMuPDF + 公式页/扫描页视觉 OCR)

pdf2md-agent-skill 是什么?

pdf2md-agent-skill is a Claude Code agent skill that 让 LLM agent 高效读懂任何文档:PDF/Word/PPT/Excel 转 Markdown,PDF 智能分流(文本页 PyMuPDF + 公式页/扫描页视觉 OCR).

兼容平台✓Claude Code✓Codex CLI~Cursor
npx skills add taotaoboom/pdf2md-agent-skill

Installed? Explore more 研究与数据分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

pdf2md-agent-skill - PDF/Document to Markdown

When to Trigger

When you need to read a PDF's content, first use this skill to convert it to Markdown.

Convert the PDF to Markdown first, then use the current Agent's text reading tool to read the output file.

Trigger scenarios:

  • User provides a PDF path and asks to read, summarize, analyze, translate, or answer questions
  • Specific content from the PDF needs to be referenced
  • Tables, formulas, or references need to be extracted from the PDF

Standard Workflow

First, resolve <skill_dir> as the directory where this SKILL.md is located. Do not assume the skill is installed in ~/.claude/skills, as paths differ for Codex, custom installations, and Windows.

Execute in fixed order:

# Step 1: Convert (automatically handles all PDF types—no need to check the type)
python3 "<skill_dir>/scripts/md_convert.py" "<pdf-path>" -o "<workspace-temp-dir>/<name>.md"

# Step 2: Use the current Agent's text reading tool to read the generated .md file

Example:

python3 "<skill_dir>/scripts/md_convert.py" \
  "/path/to/some-paper.pdf" \
  -o "./some-paper.md"

Then read ./some-paper.md.

Why This Design

PDFs contain multiple page types with different processing strategies. The script automatically decides per page—you don't need to worry:

Page TypeScript StrategyDescription
Normal text pagePyMuPDF extractionFast, free, with paragraph merging + dual-column sorting + header filtering
Formula-heavy pagesArk Visual OCRFormulas rendered as LaTeX (\( E_i \)), avoiding fragmentation
Scanned pagesArk Visual OCRRender image + visual model recognition
Mixed pagesPer-page automatic routingOne paper: only OCR formula pages, balancing speed and quality

Smart hybrid strategy: The script detects mathematical symbol density per page. Formula pages (density >1.5%) are automatically OCR'd to LaTeX, text pages use PyMuPDF.

Forbidden actions:

  • ❌ Do not check the PDF type to decide the call method—just invoke it directly; the script handles everything automatically
  • ❌ Do not use bare markitdown command to convert PDF (the default pdfminer backend loses spaces)
  • ❌ Do not read PDF as plain text directly
  • ❌ Do not omit the -o parameter (it is required)

Parameters

ParameterDescriptionWhen to Use
inputInput file path (required)Always
-o, --outputOutput .md path (required)Always
--ocrForce full document LLM OCROnly when auto-detection clearly fails (rare)
-m, --modelVision model, default doubao-seed-1-6-flash-250828When switching models
--allow-partialAllow exit success even if OCR pages are missingOnly when the user explicitly accepts incomplete output
--no-llmDisable LLM enhancement for non-PDF formatsOnly for non-PDF formats
--versionShow version numberWhen querying version

For default calls, do not add any optional parameters:

python3 "<skill_dir>/scripts/md_convert.py" input.pdf -o ./out.md

Non-PDF Formats

Word/PPT/Excel/images are also supported, using the markitdown native path:

python3 "<skill_dir>/scripts/md_convert.py" report.docx -o ./report.md

Such formats can also be read directly with the appropriate document tool; convert to Markdown when a unified structure is needed.

Environment & Dependencies

Environment variables:

  • ARK_API_KEY - Required when formula-heavy pages, scanned pages, or empty text pages trigger visual OCR. Not needed for text-only PDFs that don't trigger OCR.
  • ARK_BASE_URL - Optional, defaults to https://ark.cn-beijing.volces.com/api/v3. Ark is verified; other endpoints must be compatible with Chat Completions, visual input, and data URLs—verify before use.

Dependencies:

  • pymupdf (PDF text extraction + rendering)
  • openai (Ark vision model client)
  • markitdown (non-PDF format backend)

Requires Python 3.10+.

Error Handling

ErrorCauseHow to Handle
ARK_API_KEY not setFormula/scanned/empty pages need visual OCRSet the key, or use input that doesn't trigger OCR
File not foundWrong path or unquoted spacesWrap the path in quotes
openai/markitdown/pymupdf not installedMissing dependenciespip install <package-name>
PDF is encryptedPDF has a passwordDecrypt the PDF first, then convert
OCR pages detected as missingInvalid Key / network / model nameCheck the error and retry; use --allow-partial only if the user explicitly accepts incomplete output
Output path cannot be the same as input fileOutput would overwrite the originalSpecify a different path for the Markdown
Conversion succeeds but content is emptyPossibly a pure-image PDF misidentifiedAdd --ocr to force OCR and retry

If conversion fails: Do not keep retrying the same command; first read the stderr error to locate the issue.

Output Conventions

  • The script writes Markdown to the file specified by -o, and outputs processing logs (page type, progress) to stderr
  • On success, the last line is: OK: <input> -> <output> (XX KB)
  • If any OCR page fails, the script returns a non-zero exit code by default; use --allow-partial explicitly only to accept incomplete output
  • After conversion, use a text reading tool to read the output file, then continue working based on the content

Division of Labor with Other Tools

ScenarioTool
Read PDF contentThis skill (must use)
Read Word/PPT/ExcelThis skill or the current Agent's document tool
Read plain text/code/MarkdownThe current Agent's text reading tool

相关技能