Free Thanksgiving & Christmas printables · Holiday Bundle: 3 kits for $15

How to Convert a PDF to Markdown for RAG and AI Agents

By Wood Between Studio · · 1 min read

If you want a language model to answer questions about a report, a paper or a policy, you need the text out of the PDF first. A raw copy-paste or a naive text extract usually breaks headings and lists, which makes embeddings worse and answers vaguer.

Markdown is a good target: models already understand # headings and lists, and it's easy to chunk.

What "clean" means

  • Headings should come out as headings, not as a slightly larger line of body text.
  • Broken lines inside a paragraph should be joined.
  • Lists should still be lists.
  • Page numbers and running headers can usually go.
  • Metadata (title, author, date) should travel with the document.
  • If the PDF is a scan with no text layer, the extract will be empty — flag it for OCR instead of pretending it worked.

Page ranges save money and context

You rarely need all 400 pages of a manual. Extract 1-8 or 12-20 and send only that to the model.

A tool we use for this

We published a PDF to Markdown Actor on Apify that takes a list of PDF URLs and returns Markdown, plain text, metadata and optional per-page text. Password-protected PDFs work. Scanned files are flagged with likelyScanned: true rather than billed as if they had text. It costs $2 per 1,000 PDFs; failed downloads are free.

```python import os from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"]) run = client.actor("wood-between-studio/pdf-to-markdown").call(run_input={ "urls": ["https://arxiv.org/pdf/1706.03762"], "pageRange": "1-5", "includePerPageText": True, }) items = client.dataset(run["defaultDatasetId"]).list_items().items ```

Docs: PDF to Markdown. Apify's free monthly credit covers a lot of small runs.

Make room for what matters: extract the pages you need, then ask the question.

Pinterest image for this guide: PDF to Markdown for RAG. Keep the headings. Skip scanned PDFs or OCR them. Use page ranges. Don't dump raw text. Batch the URLs.
Save this guide for later. The image above is sized for Pinterest.

Get new free printables and sale alerts

Join the Wood Between Studio list for an occasional email when we add free printables, new designs or a sale. Unsubscribe anytime.

Subscribe free by email

Sign-up is handled by Gumroad, our shop platform. Make room for what matters.