The Document Agent

Guide

PDF to Markdown: How to Convert PDFs for LLM and RAG Pipelines

Markdown is the format most LLM pipelines want, and PDF is the format most documents arrive in. What a converter has to get right between the two, the kinds of tool that do it, and how to check the output before it reaches an index.

The Document Agent · Updated November 28, 2026Document Parsing and OCRAgent PipelineExtraction Evals

Why convert PDFs to Markdown

A PDF stores where characters sit on a page, not what they mean. There is usually no paragraph, no heading and no table in the file, only text runs at coordinates, and often no text at all when the page is a scan. Converting to Markdown means recovering that meaning: which lines are headings, what order the text is read in, which grid of words is a table, and what to drop (page numbers, running headers, crop marks).

Markdown is a popular target for LLM and retrieval-augmented generation (RAG) pipelines for three practical reasons. It keeps the structure a model needs (headings, lists, tables, emphasis) with very little markup, so it costs fewer tokens than HTML or a nested JSON layout tree. Language models read and write it fluently. And its headings give a chunker natural boundaries, so a retrieved passage arrives with the section it belongs to rather than cut mid-table.

It is not the right output for every job. If the goal is specific values (an invoice total, a policy number, each line item), extract them to a schema as JSON instead, or as well. If you need to show a user where an answer came from on the page, keep a JSON sidecar with page numbers and bounding boxes, because Markdown has nowhere to put them.

Go deeper: Intelligent Document Processing (IDP): A Guide for Engineering Teams

What a converter has to get right

Most bad Markdown traces back to a handful of PDF features. Check each of these on your own files before trusting any converter:

PDF contentWhat good output looks likeCommon failure
Headings#, ## and ### levels that match the document's outlineEvery bold line becomes a heading, or no headings at all; levels guessed from font size come out flat or inverted
Multi-column textEach column read top to bottom, in orderLines from two columns interleaved into sentences that make no sense
TablesA Markdown table with every row and cell in placeRows dropped, cells shifted by one column, merged cells repeated or lost, or the whole table flattened to a line of words
Running headers, footers, page numbersRemoved, or kept once as metadataRepeated on every page and stitched into the middle of paragraphs
Scanned pagesText recovered by OCREmpty output, because the page has no text layer to read
EquationsLaTeX between $ delimitersSymbols scrambled, superscripts and subscripts lost
Images and chartsAn image reference or a short description, in placeDropped silently, or chart labels spilled into the text as loose words
Hyphenation, ligatures, encodingWords rejoined and normalised ("fi" becomes "fi")Split words, broken ligatures and mojibake that hurt search and embeddings

Tables need extra care because Markdown's own table syntax (the GitHub-flavoured pipe table) has no merged cells and no lists or paragraphs inside a cell. Converters handle that differently: some repeat a merged value into every cell it spans, some leave cells blank, and some emit an HTML table inside the Markdown. Check which one your converter does, and whether the model or chunker downstream copes with it.

Go deeper: Reading Order Detection in Multi-Column Document Layouts · Table Extraction Accuracy from Scanned PDFs · Character Encoding and Unicode Normalization Failures in Document Parsing · Document Image Preprocessing for OCR Accuracy

Four ways to convert PDF to Markdown

PDF to Markdown converters fall into four broad groups. They differ less in the Markdown they write than in how they work out the structure behind it, and that decides which documents they handle well.

ApproachExamplesGood fitWatch out for
Text-layer librariesPyMuPDF4LLM, Microsoft's MarkItDownBorn-digital PDFs with simple layouts (reports, exported documents) at high volume, on a CPUOnly as good as the text layer: no output from scans without an OCR step, and weak on complex tables and columns
Layout-model pipelinesDocling, Marker, MinerUMixed documents with tables, columns, equations and some scans, run on your own hardwareSlower and heavier (a GPU helps); a chain of models where an early layout error carries through; check the licence of both code and model weights
Vision-language modelsA general multimodal model prompted to transcribe each page image as MarkdownLayouts the other tools get wrong, handwriting, quick prototypesCost and latency per page, pages that are summarised or invented rather than transcribed, and long tables cut short
Managed APIsLlamaParse, Mistral OCR, Azure AI Document Intelligence (layout model with Markdown output)Teams that want no infrastructure and steady per-page usageDocuments leave your infrastructure, pricing per page or credit, and behaviour that changes when the vendor updates a model

Pandoc, the usual answer for converting between document formats, does not read PDF as an input format, so it cannot do this job on its own. The same goes for most general-purpose online converters, which are built for one-off files rather than a pipeline, and which upload your document to someone else's server.

Many teams end up combining approaches: a fast text-layer library for the clean, born-digital majority, and a layout model, a vision-language model or an API for scans and the pages the fast path gets wrong. Every tool here changes quickly, so check each project's documentation, licence and current pricing before choosing.

Go deeper: PDF Parsing Libraries Compared for ML Pipelines · Vision-Language Models vs Traditional OCR Engines · Hybrid Computer Vision Pipelines for Document Parsing · Multi-Column PDF and Table Extraction Accuracy Across Leading APIs

How to convert PDFs to Markdown in a pipeline

Converting one file is a single command (for example, markitdown report.pdf -o report.md with MarkItDown's command-line tool, or pymupdf4llm.to_markdown("report.pdf") in Python). Converting every file that reaches a production pipeline takes a few more steps:

  1. Check for a text layer. Test each PDF, or each page, for extractable text before choosing a path. Born-digital pages can go to a fast text-layer converter; scanned or image-only pages need OCR or a vision model. Mixed files, with some pages scanned and some not, are common.
  2. Route by document type. Send the document types your fast path handles badly (tables, multi-column layouts, forms) to a heavier converter. A per-type rule is easier to reason about than one converter for everything.
  3. Convert and keep the page map. Record which page each block of Markdown came from, with page breaks or comments in the output, or positions in a sidecar file. Without it you cannot cite a source page or debug a bad answer back to the PDF.
  4. Clean up. Strip repeated headers, footers and page numbers; rejoin words hyphenated across lines; normalise Unicode; and collapse runs of blank lines. Do this in code you control, so it is the same for every converter.
  5. Validate before indexing. Flag outputs that are empty, much shorter than the page count suggests, or full of replacement characters, and send them to a fallback converter or a person rather than into the index.
  6. Chunk on structure. Split on headings and keep tables whole, carrying the heading path into each chunk. A chunk that starts halfway through a table, or loses the section it came from, retrieves badly however good the conversion was.

Go deeper: Orchestration Patterns for Document Ingestion Pipelines · Stateful Document Processing for Multi-Page Reasoning Tasks · Handwritten Text Recognition in Production Document Pipelines

How to test a PDF to Markdown converter

Public benchmarks are run on someone else's documents, and the same converter can do very well on one document type and poorly on another. Before choosing, run the candidates on a sample of your own PDFs:

  • Pick 20 to 50 real files that cover your mix: clean exports, scans, phone photos, long tables, multi-column pages, forms. Weight the sample towards the documents that matter most, not the easy ones.
  • Correct the Markdown by hand for a subset of pages and compare each converter's output with it, rather than judging by eye from a rendered preview.
  • Check tables cell by cell: count rows and compare values. A table with one dropped row looks fine at a glance and gives wrong answers later.
  • Read multi-column pages end to end to catch interleaved columns, and look for headers and footers left in the body.
  • Run the downstream task too: ask the questions your users ask against an index built from each converter's output, and compare the answers.
  • Measure pages per minute, hardware needs and cost per page at your real volume. A converter that needs a GPU per worker changes the cost of the whole pipeline.
  • Confirm where documents are processed. For regulated or confidential files, a self-hosted converter may be the only option, whatever the accuracy of a managed API.

Go deeper: Ground Truth Dataset Construction for Document Extraction Tasks · Benchmarking Document Extraction Accuracy on Production Document Sets · Self-Hosted Document AI Deployment for Regulated Industries · Cost Modeling for High-Volume Document Processing at Enterprise Scale

Frequently asked questions

Can Pandoc convert PDF to Markdown?

Not on its own. Pandoc does not accept PDF as an input format. Convert the PDF with a PDF-aware tool first; Pandoc can then turn that Markdown into other formats if you need them.

What is the best way to convert PDF to Markdown for an LLM?

It depends on the documents. Born-digital PDFs with simple layouts convert well with a fast text-layer library. Tables, multi-column layouts and scans need a layout-model converter, a vision-language model or a managed API. Test a few candidates on a sample of your own PDFs and compare the output against hand-corrected Markdown.

How do I convert a scanned PDF to Markdown?

A scanned page is an image with no text layer, so it needs OCR or a vision-language model before it can become Markdown. Layout-model converters and most managed APIs include OCR; text-layer libraries generally need an OCR step added. Image quality matters, so clean up skewed or low-resolution scans first.

How are tables represented in Markdown?

Usually as pipe tables, which cannot express merged cells or hold lists and paragraphs inside a cell. Some converters emit HTML tables inside the Markdown for complex tables instead. Check what your converter produces and whether your chunker and model handle it.

Is it safe to use an online PDF to Markdown converter?

An online converter uploads your file to its server. For anything confidential, check its privacy and data retention terms first, or use an open-source converter that runs on your own machine.

Further reading