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 Type | Script Strategy | Description |
|---|---|---|
| Normal text page | PyMuPDF extraction | Fast, free, with paragraph merging + dual-column sorting + header filtering |
| Formula-heavy pages | Ark Visual OCR | Formulas rendered as LaTeX (\( E_i \)), avoiding fragmentation |
| Scanned pages | Ark Visual OCR | Render image + visual model recognition |
| Mixed pages | Per-page automatic routing | One 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
markitdowncommand to convert PDF (the default pdfminer backend loses spaces) - ❌ Do not read PDF as plain text directly
- ❌ Do not omit the
-oparameter (it is required)
Parameters
| Parameter | Description | When to Use |
|---|---|---|
input | Input file path (required) | Always |
-o, --output | Output .md path (required) | Always |
--ocr | Force full document LLM OCR | Only when auto-detection clearly fails (rare) |
-m, --model | Vision model, default doubao-seed-1-6-flash-250828 | When switching models |
--allow-partial | Allow exit success even if OCR pages are missing | Only when the user explicitly accepts incomplete output |
--no-llm | Disable LLM enhancement for non-PDF formats | Only for non-PDF formats |
--version | Show version number | When 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 tohttps://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
| Error | Cause | How to Handle |
|---|---|---|
ARK_API_KEY not set | Formula/scanned/empty pages need visual OCR | Set the key, or use input that doesn't trigger OCR |
File not found | Wrong path or unquoted spaces | Wrap the path in quotes |
openai/markitdown/pymupdf not installed | Missing dependencies | pip install <package-name> |
PDF is encrypted | PDF has a password | Decrypt the PDF first, then convert |
OCR pages detected as missing | Invalid Key / network / model name | Check the error and retry; use --allow-partial only if the user explicitly accepts incomplete output |
Output path cannot be the same as input file | Output would overwrite the original | Specify a different path for the Markdown |
| Conversion succeeds but content is empty | Possibly a pure-image PDF misidentified | Add --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-partialexplicitly 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
| Scenario | Tool |
|---|---|
| Read PDF content | This skill (must use) |
| Read Word/PPT/Excel | This skill or the current Agent's document tool |
| Read plain text/code/Markdown | The current Agent's text reading tool |