PDF to Markdown for LLMs
How to convert PDFs to Markdown for LLMs
An LLM reads Markdown well, and a retriever can split it at its headings. Convert the PDF first, keep the tables whole, and your pipeline starts from clean text.
Why convert a PDF before it reaches the LLM
Text pulled straight out of a PDF has no structure. Headings look like ordinary lines, two columns are read as one, and a table becomes a run of numbers. The model then answers from text it cannot read in order.
Markdown fixes the three things a pipeline needs most: headings to split on, tables that stay tables, and text in reading order.
What to check before you index the output
- Chunk boundaries. Split at headings, so a chunk holds one topic and not half of two.
- Whole tables. A table cut mid-row gives the retriever half a row. Keep each table in one chunk, or repeat its header row.
- Exact numbers. A converter that rewrites text can change a figure. Compare a few numbers with the source page.
- Scanned pages. A page with no text layer needs OCR. Without it the page is missing from the index.
- Page references. If an answer must cite its source, the text needs a way back to the page it came from. The sample on the docs2md home page shows each Markdown block linked to its box on the page.
Convert PDFs to Markdown with an API
A pipeline cannot wait for someone to upload files by hand. docs2md has an API that uses an API key, so a script can send an archive in batches and collect the Markdown files.
Try one file in the app first. The output you see there is the output the API returns.
Ways to prepare PDFs for an LLM
| Method | Works well for | Watch out for |
|---|---|---|
| Plain text extraction | Simple PDFs with one column and no tables | Headings, tables and column order are lost |
| Send the PDF straight to a multimodal LLM | A few documents | The cost is per page and repeats on every re-run. The model can also rewrite numbers. |
| An LLM that writes Markdown page by page | A few complex pages | Same per-page cost, multiplied by every archive and every re-run |
| A conversion service such as docs2md | Archives with tables and scans | You upload the file, so check the privacy terms first |
The cost of a whole archive
Prepare 9.6 million pages and the price per page decides the project. Every re-run, such as a new chunking rule or a backfill, costs the same again.
docs2md copies the text from the file instead of asking a model to write it, which is why the price stays flat.
Questions
Is it free?
You can try it free. Upload a file in the app and read the result before you decide anything.
Does it keep tables?
Yes. Tables come out as Markdown tables, so a row stays a row.
Can it convert scanned PDFs?
Yes. Pages without a text layer go through OCR.
Which other files can I convert?
PDF, Word (.docx), PowerPoint (.pptx), Excel (.xlsx), CSV, plain text and images (PNG, JPG, TIFF, BMP, WebP). See the guides for PDF, DOCX and PPTX.
Convert a PDF for your pipeline
Upload a file and read the Markdown your retriever would index.