pymupdf/PyMuPDF

Layout-aware document engine for AI and a feature-rich Python toolkit for extracting, rendering and editing PDFs and other documents. Since version 2.0, its ML-based layout analysis turns PDFs and Office files into high-quality Markdown for RAG and agents, running fast on CPU and grounding every result to its source page.

What it solves

PyMuPDF tackles the messy reality of working with PDFs and other documents programmatically. It can extract text with precise positioning, detect and extract tables, render pages to images, run OCR on scanned files, edit and annotate documents, and convert them into clean Markdown or JSON that AI systems can consume. This saves developers from building these capabilities from scratch and makes documents useful for retrieval-augmented generation (RAG) and large language model (LLM) pipelines.

How it works

PyMuPDF is a Python binding around the MuPDF C library, which provides a fast and accurate rendering engine. It works directly on the document's internal structure, giving you fine-grained control over every element. You can open a PDF, loop through pages, and call methods like page.get_text() to read text with metadata (font, size, color, position), or page.find_tables() to locate tables and export them as Markdown or pandas DataFrames. For AI use, doc.to_markdown() uses an ML-based layout analysis (running on CPU via ONNX) to reconstruct reading order, handle multi-column layouts, and produce clean, grounded Markdown. Everything runs locally on your machine – no cloud calls or telemetry – and you can optionally add OCR (Tesseract or the faster RapidOCR) or unlock Office document support (with a license key) to handle DOCX, XLSX, PPTX, and more.

Who it's for

PyMuPDF is for developers and data teams who need to process documents programmatically. It's especially useful for people building RAG pipelines, AI agents, document search systems, or automated document workflows, as well as for anyone who needs to extract, edit, or convert PDFs in Python. Because it runs fully offline, it fits well in regulated industries, on-premise deployments, and air-gapped environments.

Highlights

  • Fast and accurate – built on the C-based MuPDF engine, with 10-50x speed improvements over pure-Python libraries.
  • Layout-aware Markdown – ML-powered conversion that preserves reading order, tables, and page structure for LLM-ready output.
  • Comprehensive extraction – text with full metadata, tables, images, and OCR support for scanned documents.
  • Full document editing – annotate, redact, highlight, merge, split, and create PDFs from Markdown.
  • Local and private – processes entirely on-device, no data leaves your environment.
  • Wide format support – reads PDF, XPS, EPUB, images, and (with optional Office) Word, Excel, PowerPoint, and Korean Office formats.

Related

  • Project
  • Project
  • Project
  • Project
  • Project