---
title: "Discussion on \"How to Convert PDF to Markdown for LLMs in Python (3 Free Libraries Tested)\" | Hashnode"
description: "Discussion on \"How to Convert PDF to Markdown for LLMs in Python (3 Free Libraries Tested)\". We converted the same 15-page paper with pymupdf4llm, MarkItDown and pypdfium2. Speed, heading and spacing results, and when to use each."
url: "https://hashnode.com/posts/how-to-convert-pdf-to-markdown-for-llms-in-python-3-free-libraries-tested/6ab30268ba38c235e510130a"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to Convert PDF to Markdown for LLMs in Python (3 Free Libraries Tested)](https://kanto-labs.hashnode.dev/how-to-convert-pdf-to-markdown-for-llms-in-python-3-free-libraries-tested?utm_source=hashnode&utm_medium=feed)

We converted the same 15-page paper with pymupdf4llm, MarkItDown and pypdfium2. Speed, heading and spacing results, and when to use each.

Sep 22 · 6 min read · kanto-labs.hashnode.dev  
Read the article

-   [#python](https://hashnode.com/tag/python)
-   [#llm](https://hashnode.com/tag/llm)
-   [#rag](https://hashnode.com/tag/rag)
-   [#ai](https://hashnode.com/tag/ai)

## Written by

[Kanto Labs](https://hashnode.com/@kanto-labs)

@kanto-labs

  
[View profile](https://hashnode.com/@kanto-labs)

Practical tutorials on web data, RAG document prep and SEO tooling.

Kanto Labs builds small, reliable tools for web data, document-to-Markdown for RAG, and SEO audits. Find our tools at apify.com/kantolabs.

## Responses 2

Markdown supported · ⌘↵ to post

[Mihai\_LeanZero](https://hashnode.com/@mihaileanzero)

[Sep 23](https://hashnode.com/posts/how-to-convert-pdf-to-markdown-for-llms-in-python-3-free-libraries-tested/6ab30268ba38c235e510130a/comment/6ab320771c81668bb0d1ba9b)

Good catch on the average-word-length heuristic, though it can still pass while being wrong: two-column academic PDFs run through the same kind of converters sometimes come out with correct spacing but scrambled reading order, column A then column B interleaved wrong, and the average stays around 5.5 chars because the words themselves are intact, it's just the sequence that's broken. Worth pairing the length check with something order-sensitive rather than relying on it alone. Also curious about pymupdf4llm's page markers on rotated or scanned pages, have you checked those against the real page breaks, or just on clean digital PDFs like the arXiv one here?

[Kanto Labs](https://hashnode.com/@kanto-labs)

[Sep 23](https://hashnode.com/posts/how-to-convert-pdf-to-markdown-for-llms-in-python-3-free-libraries-tested/6ab30268ba38c235e510130a/comment/6ab320771c81668bb0d1ba9b#reply-6ab375458646f138f74e3e26)

fair, but that check was only ever meant to catch the glued-words problem, not ordering, that's a different failure. for column order the quickest thing i've found is sorting PyMuPDF's text blocks column-first and checking the output follows that sequence, interleaving shows up right away. pymupdf4llm already tries to detect columns so i'd worry more about pypdf there. page markers on scanned/rotated pages i honestly haven't tested, only clean digital stuff like the arxiv paper. scanned pages have no text layer anyway so without OCR you'd just get an empty marker. will try a couple and update the post
