CyberMax
Home › Blog

How to convert PDFs to Markdown for LLMs and RAG (with a real test)

27 September 2026 · by CyberMax · 6 min read

Language models read text, not pages. Hand a model a PDF and something has to turn fonts, columns, headers, footers and tables into a stream of characters first, and that step decides how much the model understands. Markdown is the format that keeps the structure (headings, lists, tables) in a form models are trained on, at a fraction of the size.

A real test: NIST's Cybersecurity Framework 2.0

We converted the official PDF of the NIST Cybersecurity Framework 2.0 (CSWP 29, 32 pages) with one API call on 27 September 2026:

MeasureResult
PDF size1,518,858 bytes
Markdown65,426 characters
Approximate tokens16,357
Conversion time1,451 ms (1.7 s end to end)
Structure keptpage markers, headings, lists and Table 1 as a Markdown table
NIST CSF 2.0: file size vs what the model reads
PDF file: 1,483.3 KBPDF file1,483.3 KBMarkdown text: 63.9 KBMarkdown text63.9 KB

1,518,858-byte PDF → 65,426 characters of Markdown (~16,357 tokens). Converted by Leafmelt on 27 Sep 2026 in 1,451 ms.

At about 16,000 tokens the whole framework fits in the context window of current models with room to spare, and for retrieval (RAG) each ### heading is a natural chunk boundary. Here is the start of Table 1 as it came out:

Table 1. CSF 2.0 Core Function and Category names and identifiers

| Function | Category | Category Identifier |
| - | - | - |
| Organizational Context | GV.OC |
| Risk Management Strategy | GV.RM |
| Roles, Responsibilities, and Authorities | GV.RR |

Honest note: in this table the merged "Function" cells (Govern, Identify and so on) are not repeated on each row, so the first column shifts. Merged cells are the hardest part of any PDF table; if a table matters, check it before you index it.

Try it: convert the NIST CSF 2.0 PDF (free, no key)

The PDFs that fail (and how to spot them)

We also tried the IRS Form W-9 PDF. It converted in about a second and came back with 85 characters for 6 pages: the form is an XFA form, whose text lives in a script layer rather than on the page. Scanned PDFs (photos of paper) fail the same way because there is no text layer at all. A good converter tells you instead of returning an empty string silently: Leafmelt sets emptyText: true with a note, so your pipeline can route those files to OCR.

Five rules for LLM-ready documents

  1. Keep structure. Headings and tables in Markdown let the model and your chunker see where topics start and end.
  2. Count tokens before you send. A token count per document tells you whether to chunk, summarise or send whole.
  3. Drop the noise. Repeated headers, footers and page numbers waste tokens in every chunk.
  4. Flag empty conversions. Scans and XFA forms need OCR; do not index an empty page.
  5. Keep the source link with every chunk so answers can cite the page they came from.

Convert documents by API

Leafmelt converts up to 5 documents per call, by URL or upload: PDF, Word, Excel, OpenDocument, Apple Numbers, CSV, HTML and XML, up to 10 MB each. You get clean Markdown with headings and tables kept, the character and token counts, the document metadata and the empty-text flag. The same key works as a remote MCP server, so an agent can read a document mid-conversation.

curl "https://leafmelt.cybermax-tools.workers.dev/api/convert?url=https://nvlpubs.nist.gov/nistpubs/CSWP/NIST.CSWP.29.pdf"

Published prices on 27 September 2026 for PDF extractors on the Apify Store range from $0.005 to $0.02 per PDF plus a per-page fee. Leafmelt is free for 50 calls a day, then $19/month for 3,000 calls (up to 5 documents each), $49/month for 10,000, or $5 pay-as-you-go for 750. Need web pages rather than files? Fieldwright turns any URL into clean Markdown.

Source document: NIST CSWP 29, The NIST Cybersecurity Framework (CSF) 2.0, 26 February 2024 (US Government work).

More from the CyberMax blog