MarkItDown is Microsoft’s command-line tool for converting documents — PDFs, Office files, images, HTML, and more — into clean Markdown, which makes it handy for feeding documents into an LLM pipeline. Install it with PDF support first:
pip install "markitdown[pdf]"
Converting a Single PDF
To convert one PDF and save the output, use the -o flag:
markitdown document.pdf -o output.mdSince MarkItDown prints to stdout by default, plain shell redirection works just as well:
markitdown document.pdf > output.mdConverting All PDFs in a Folder
The CLI only targets one file at a time, so batch-converting a directory means wrapping it in a loop.
Bash / Zsh (Linux & macOS):
for file in *.pdf; do
markitdown "$file" -o "${file%.pdf}.md"
donePowerShell (Windows):
Get-ChildItem *.pdf | ForEach-Object {
markitdown $_.FullName -o ($_.BaseName + ".md")
}Batch Converting with the Python API
For more control — say, catching per-file failures instead of letting one bad PDF kill the whole batch — call MarkItDown directly from Python:
from pathlib import Path
from markitdown import MarkItDown
md = MarkItDown()
input_dir = Path("./my_pdfs")
output_dir = Path("./converted_markdown")
output_dir.mkdir(parents=True, exist_ok=True)
for pdf_path in input_dir.glob("*.pdf"):
try:
result = md.convert(str(pdf_path))
output_file = output_dir / f"{pdf_path.stem}.md"
output_file.write_text(result.text_content, encoding="utf-8")
print(f"Converted: {pdf_path.name} -> {output_file.name}")
except Exception as e:
print(f"Failed to convert {pdf_path.name}: {e}")