← All guides

How to convert a PDF to Markdown for LLMs and RAG

Markdown has become the preferred way to feed PDF content to an LLM: it keeps headings, lists, and tables as structure the model can use, without the noise of raw PDF text. For a quick, one-off conversion of a text-based PDF, PDFMoka's PDF to Markdown converter does it in your browser with no upload, good when you just need to paste a document into a prompt. For production RAG pipelines processing many documents, a purpose-built Python library (PyMuPDF4LLM, Docling, Marker, or Microsoft's MarkItDown) will give you better structure preservation and integrations. The same hard rule as every PDF-text task applies: this works on PDFs with a real text layer; scanned/image PDFs need OCR first. Here is how to choose.

Why Markdown for LLMs (not plain text)

Plain text extraction throws away structure: you lose the signal that something was a heading, a list, or a table. Markdown keeps that structure in a lightweight, token-efficient form the model understands. For RAG specifically, that structure matters twice: it improves how you chunk the document (splitting on headings rather than arbitrary character counts), and it improves retrieval quality because the chunks are semantically coherent. Garbage in, garbage out, the quality of your RAG answers is capped by the quality of your document parsing.

The hard gate again: text layer vs scan

A digitally-created PDF has selectable text, and conversion reads it directly. A scanned PDF is an image with no text, so a plain converter returns nothing usable; you need OCR to recognize the characters first. PDFMoka's converter reads the text layer and does not OCR, so for scanned documents it will return empty or incomplete output, and we would rather say so than hand you a broken file. For scans, either run OCR first (Tesseract, ocrmypdf, or a cloud OCR service) or use one of the libraries below that have OCR built in.

Quick / one-off: browser conversion

If you have a text-based PDF and just need Markdown to drop into a prompt or a vector store once, convert it in your browser with PDFMoka. No Python environment, no model downloads, no cold start, and the file is never uploaded, which matters when the PDF is an internal document you would not paste into a random web service. This produces a clean, simplified Markdown rendering suitable for most text-heavy documents. For heavily structured PDFs (complex multi-column layouts, intricate tables), a specialized library will do better; see the next section.

Production / at scale: pick a library

For a pipeline that ingests many PDFs, use a dedicated tool. The landscape as of 2026, briefly and honestly:

  • PyMuPDF4LLM is the fast, lightweight default for native (text-based) PDFs. One function, to_markdown(), no GPU, processes pages in milliseconds. Best first try when your PDFs have a clean text layer.

    pip install pymupdf4llm
    import pymupdf4llm
    md = pymupdf4llm.to_markdown("input.pdf")
  • Docling (IBM Research) is the pick when table fidelity matters (financial reports, scientific papers). It uses a table-transformer model that preserves merged cells and complex column groups better than lightweight parsers, and it has first-class LlamaIndex and LangChain integrations. Heavier, but strong for enterprise RAG.

  • Marker is a good general-purpose "does everything reasonably well" option across many document types, with an optional LLM-assisted mode for accuracy-critical documents.

  • MarkItDown (Microsoft) is handy when your inputs are mixed formats (PDF, DOCX, XLSX, PPTX), converting all of them to Markdown with a single tool; useful when the PDF is only part of a broader document pipeline.

verify against current docs: this is a fast-moving space, libraries add features (auto-OCR, ML backends, new integrations) frequently, and benchmark rankings shift. Confirm the current install command, API, and capabilities of whichever tool you pick before building on it. Treat any specific accuracy claim as something to re-benchmark on your own documents.

Honest guidance on which to use

  • One text-based PDF, need Markdown now: browser converter, done.
  • RAG pipeline, mostly text-heavy native PDFs: start with PyMuPDF4LLM (fast, light); move up only if quality isn't there.
  • Tables are critical to your answers: Docling.
  • Mixed input formats (PDF + Office): MarkItDown.
  • Scanned documents: OCR first (or a tool with built-in OCR); a text-layer-only converter will not work.

A realistic expectation-setter: no converter, ours or a library, produces perfect Markdown from an arbitrarily complex PDF. Multi-column academic papers, dense tables, and unusual layouts all produce artifacts you will want to clean. For RAG, budget for a validation and cleanup step rather than assuming clean input.

Related directions

References