document2md.pymupdf_backend

Converts a born-digital PDF to Markdown by reading its own embedded text layer with pymupdf4llm, instead of running mineru’s OCR.

Convert a born-digital PDF (one that already carries an embedded text layer) to Markdown by reading that text layer directly with pymupdf4llm, instead of running mineru’s OCR/layout models on it. Orders of magnitude faster than the mineru backend and needs no models, at the cost of slightly worse structure; mineru remains the reference backend where it is installed (see document2md.batch.BatchConverter’s auto resolution).

PyMuPDF and pymupdf4llm are AGPL-3.0 licensed; document2md itself stays Apache-2.0 (see the README’s Install section).

pymupdf/pymupdf4llm are imported inside the functions below, never at module level, so this module can still be imported (for autodoc, or by BatchConverter probing has_text_layer) when the package is installed with –no-deps and neither is present.

_require_pymupdf() → None[source]

Raise RuntimeError with an actionable message if pymupdf4llm isn’t installed, instead of letting the import inside convert_to_markdown fail opaquely.

has_text_layer(pdf_path: Path) → bool[source]

Whether pdf_path is born-digital enough for the pymupdf backend: at least MIN_TEXT_PAGE_FRACTION of its pages each have at least MIN_CHARS_PER_PAGE non-whitespace characters of extractable text. A fully scanned PDF fails; a mostly-digital document with a few scanned inserts still passes.

convert_to_markdown(pdf_path: Path, md_path: Path) → None[source]

Convert a born-digital PDF to Markdown by extracting its embedded text layer with pymupdf4llm — headings inferred from font sizes, Markdown tables via PyMuPDF’s table finder, reading order handled — instead of running mineru’s OCR/layout models on it.

Images are not extracted (no <md stem>_images/ directory is produced), unlike the mineru backend.