How pymupdf/pymupdf4llm works
PyMuPDF4LLM turns documents into Markdown, JSON, or plain text for LLM and retrieval workflows. The main path is a caller invoking the conversion API, which extracts and structures page content, selectively applies OCR, and renders output; batch conversion and layout-aware chunking are additional capabilities. The graph includes documented features whose implementation was not sampled, but omits uncertain internal links. Source excerpts and the index support the cited relationships; README-only links represent documented capabilities.
Main entry points: chunking/__init__.py Chunking API · src/__init__.py Conversion API · pymupdf_rag.py Page extraction · analyze_page.py OCR decision
Components 22
Entry points
- Conversion API
src/__init__.py - Batch converter
src/batch_converter.py - Command line
src/__main__.py
Document extraction
- Page extraction
src/helpers/pymupdf_rag.py - Layout analysis
src/helpers/document_layout.py - Column ordering
src/helpers/multi_column.py - Text lines
src/helpers/get_text_lines.py - HTML tables
src/helpers/table_html/reconstruct.py
OCR
- OCR decision
src/ocr/analyze_page.py - OCR features
src/ocr/compute_ocr_features.py - OCR execution
src/ocr/exec_ocr_interface.py - OCR backends
src/ocr/rapidocr_391_backend.py
Chunking
- Chunking API
src/helpers/chunking/__init__.py - Sentence builder
src/helpers/chunking/sentence_builder.py - Boundary scoring
src/helpers/chunking/boundary_scorer.py - Chunk assembly
src/helpers/chunking/chunk_assembler.py - Chunk models
src/helpers/chunking/models.py - Chunked document
src/helpers/chunking/chunked_document.py - Chunk serializer
src/helpers/chunking/serializer.py
Integrations
- LlamaIndex reader
src/llama/pdf_markdown_reader.py
Other components
- Document caller
- RAG or LLM consumer
Connections 24
- Document caller → Conversion API: calls
README.md - Conversion API → Page extraction: converts documents
README.md - Page extraction → Layout analysis: analyzes layout
README.md - Page extraction → Column ordering: orders columns
README.md - Page extraction → HTML tables: renders tables
README.md - Page extraction → OCR decision: selects OCR
README.md - OCR decision → OCR features: uses features
src/ocr/analyze_page.py - OCR decision → OCR execution: requests OCR
- OCR execution → OCR backends: uses backend
- Document caller → Batch converter: submits documents
- Batch converter → Conversion API: calls converter
src/batch_converter.py - Document caller → Command line: runs command
- Conversion API → Chunking API: offers chunking
README.md - Chunking API → Sentence builder: builds units
src/helpers/chunking/__init__.py - Chunking API → Chunk assembly: assembles chunks
src/helpers/chunking/__init__.py - Sentence builder → Chunk models: creates units
src/helpers/chunking/sentence_builder.py - Chunk assembly → Chunk models: uses models
src/helpers/chunking/chunk_assembler.py - Boundary scoring → Chunk models: scores boundaries
src/helpers/chunking/boundary_scorer.py - Chunking API → Boundary scoring: scores boundaries
src/helpers/chunking/__init__.py - Chunking API → Chunked document: returns document
src/helpers/chunking/__init__.py - Chunking API → Chunk serializer: serializes output
src/helpers/chunking/__init__.py - Conversion API → LlamaIndex reader: integrates with
README.md - LlamaIndex reader → Page extraction: renders pages
src/llama/pdf_markdown_reader.py - Conversion API → RAG or LLM consumer: supplies output
README.md