CommunityResearch & Data Analysisgithub.com

pdf2md-agent-skill

Enables LLM agents to efficiently read any document: converts PDF/Word/PPT/Excel to Markdown with intelligent PDF routing (text pages via PyMuPDF + formula/scan pages via visual OCR).

What is pdf2md-agent-skill?

This skill equips AI agents (such as Claude Code, Cursor, Codex, etc.) with the ability to convert a wide variety of document formats—including PDF, Word, PPT, Excel, and images—into Markdown. For PDFs, it employs a smart, page-by-page routing strategy: plain text pages are extracted quickly with PyMuPDF, while formula-dense pages and scanned pages are processed using the Ark visual OCR model to faithfully transcribe LaTeX and other content. This hybrid approach balances speed and accuracy, ensuring the agent receives clean, structured Markdown instead of raw, garbled text. The skill is triggered automatically whenever the agent needs to read, summarize, analyze, translate, or answer questions about a PDF or other document. It provides a simple two-step workflow: first run the conversion script with the document path and output location, then use the agent's native text-reading tool on the resulting Markdown file. Environment variables like `ARK_API_KEY` are required only when OCR is needed; plain text PDFs work without any setup.

Works with✓Claude Code✓Codex CLI~Cursor
npx skills add taotaoboom/pdf2md-agent-skill

Installed? Explore more Research & Data Analysis skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

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

Related Skills