DEV Community

Cover image for Batch-converting documents to markdown with Microsoft's markitdown
Schiff Heimlich
Schiff Heimlich

Posted on

Batch-converting documents to markdown with Microsoft's markitdown

Here's a quick tool that landed in my queue recently: microsoft/markitdown

It's a Python CLI that converts PDFs, Word docs, PowerPoint, and Excel files to Markdown. Not groundbreaking, but if you've ever had to process a folder of legacy documentation for a static site, you know the value of not doing it manually.

Two things I found useful:

Batch conversion with piping

markitdown --input document.docx --output converted/
Enter fullscreen mode Exit fullscreen mode

You can point it at a directory and it processes everything in one shot. Combine with standard Unix tools:

find ./legacy-docs -name '*.docx' | xargs -I{} sh -c 'markitdown --input {} --output ./md/'
Enter fullscreen mode Exit fullscreen mode

stdout output for scripting

markitdown document.pdf
Enter fullscreen mode Exit fullscreen mode

Dumps the markdown to stdout, which makes it easy to pipe into other text processing or redirect to specific filenames based on the input.

It's on PyPI (pip install markitdown), so it'll drop into a CI pipeline without much friction. If you've got a documentation migration on your plate and you're tired of manual conversions, it's worth a look.

https://github.com/microsoft/markitdown

Top comments (2)

Collapse
 
zuse8765 profile image
zuse0078 •

Useful angle on batch conversion. The stdout point is easy to overlook because it makes MarkItDown fit into existing Unix/CI pipelines instead of becoming a separate migration app. For legacy-docs folders, I would also log per-file failures and keep a small manifest mapping source file to Markdown output so broken conversions are easy to re-run.

Collapse
 
artiz profile image
Artem Kustikov •

Nice pattern. One thing worth knowing when you drive it with find | xargs: every file pays a fresh Python start-up plus the converter imports, which dominates on a folder of small documents.

If you want to compare, docling.rs (disclosure: I'm the author; an independent Rust port of IBM's docling, not affiliated with Microsoft) has the batch loop built in:

docling-rs --input './legacy/**/*.docx' --output ./md
Enter fullscreen mode Exit fullscreen mode

The directory tree is mirrored into ./md. A file that fails is reported and skipped, and the run exits non-zero at the end, so CI notices (--abort-on-error stops at the first failure instead). That covers the per-file failure log suggested above. In our side-by-side, one cold CLI call on a DOCX took 31 ms vs 1360 ms, and 38 DOCX files took 0.57 s vs 9.32 s warm.

There's also a MarkItDown-compatible Python API (from docling_rs.markitdown import MarkItDown) if your scripts call it from Python. Method and caveats: github.com/docling-project/docling...