AgentSkillsCN

x-convert-pdf-to-markdown

通过代理指令 Poetry 环境,利用 PyMuPDF(快速)或 marker-pdf(高精度 OCR/表格识别)将 PDF 转换为 Markdown。

SKILL.md
--- frontmatter
name: x-convert-pdf-to-markdown
description: Convert PDFs to markdown using the agent-instructions Poetry environment via PyMuPDF (fast) or marker-pdf (heavy-duty OCR/tables).

Two tools are available depending on your needs:

ToolBest ForSpeedSize
pymupdfSimple text PDFsVery fast (~12s for 7 files)~15MB
marker-pdfComplex PDFs with tables, images, OCRSlow~2GB models

Setup

Both tools are installed in the agent-instructions poetry environment:

bash
cd ~/brain/git/personal/agent-instructions
poetry install  # if not already done

PyMuPDF (Recommended for text-only PDFs)

Fast and lightweight. Use this for most PDFs.

Single File

bash
cd ~/brain/git/personal/agent-instructions
poetry run pymupdf gettext -mode layout -output "/path/to/output.md" "/path/to/file.pdf"

Batch Conversion

bash
cd ~/brain/git/personal/agent-instructions
for pdf in /path/to/pdfs/*.pdf; do
  name=$(basename "$pdf" .pdf)
  poetry run pymupdf gettext -mode layout -output "/path/to/output/${name}.md" "$pdf"
done

Options

OptionDescription
-modesimple, blocks, or layout (default: layout preserves formatting)
-outputOutput file path
-pagesPage range to extract

marker-pdf (For complex PDFs)

Use when you need OCR, table extraction, or image handling.

Single File

bash
cd ~/brain/git/personal/agent-instructions
poetry run marker_single "/path/to/file.pdf" --output_dir "/path/to/output"

Options

OptionDescription
--output_dirDirectory to save output
--output_formatmarkdown, json, html, or chunks
--page_rangeProcess specific pages, e.g., "0,5-10,20"
--force_ocrForce OCR on all text

First Run

On first use, marker downloads ML models (~2GB). This happens once.


Notes

  • Fully local: Both tools process entirely on your machine, no cloud
  • PyMuPDF: Best for clean, text-based PDFs
  • marker-pdf: Best for scanned docs, tables, or complex layouts