Skip to content

iamarunbrahma/pdf-to-markdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF to Markdown

License: MIT Python 3.9+ Dependencies: MIT-only uv Ruff

Turn PDFs into clean, structured Markdown

pdf2md extracts a PDF's structure - headings, lists, tables, code, math, links, and images - not just its raw text. It is built on the MIT-licensed pdfplumber / pdfminer.six, with no AGPL (PyMuPDF) and no heavy ML/OCR stack anywhere in the dependency tree. Install, import, and run it as pdf2md.

Install

uv sync

Usage

uv run pdf2md --pdf_path paper.pdf --out out/
# → writes out/paper.md

Features

  • Headings from document-wide font-size statistics
  • Text: paragraphs (de-hyphenated), bold / italic / inline code, super/subscript, links
  • Lists (ordered, unordered, nested), blockquotes, horizontal rules
  • Code blocks via monospace-font detection
  • Tables - ruled and borderless, as GFM pipe tables
  • Math → LaTeX - inline $…$ and display $$…$$ (heuristic)
  • Layout - multi-column reading order, rotated/landscape pages, header/footer stripping
  • Footnotes, table of contents, images, and CJK / Unicode text

Behaviour is tunable in config/config.yaml.

Optional: high-accuracy math

Core math extraction is heuristic. For accurate equations, install the opt-in ML extra (pix2tex, which pulls in BSD torch - kept out of the core so the default install stays lean):

uv sync --extra math

Limitations

  • No OCR - scanned / image-only pages yield embedded images only.
  • Math is heuristic - complex equations are best-effort (use --extra math).
  • Dense multi-table pages and right-to-left scripts may need manual review.

License

MIT - see LICENSE.