A lightweight tool to convert PDF and Word documents to Markdown, and merge multiple Markdown files together.
Convert documents to Markdown:
- PDF files → Markdown
- Word documents (.docx, .doc) → Markdown
Merge Markdown files:
- Combine multiple
.mdfiles into one - Adds source file markers and separators between files
Open the Terminal app on your Mac.
cd ~/Documents/development/markdowngetdownEvery time you want to use the tool, you need to activate its environment first:
source .venv/bin/activateYou'll know it worked when you see (.venv) at the start of your terminal prompt.
python mdg.py --helpYou should see usage information displayed.
python mdg.py convert /path/to/document.pdfThis creates document.md in the same folder as the PDF.
python mdg.py convert /path/to/document.docxThis creates document.md in the same folder as the DOCX.
python mdg.py convert /path/to/document.pdf -o /path/to/output/result.mdpython mdg.py convert /path/to/folderThis converts all PDF and DOCX files in the folder and saves them to a subfolder called output.
python mdg.py convert /path/to/folder -o /path/to/resultspython mdg.py merge file1.md file2.md file3.md -o combined.mdThis creates combined.md with all three files merged together.
python mdg.py merge /path/to/folder -o combined.mdThis merges all .md files in the folder (sorted alphabetically) into combined.md.
python mdg.py merge file1.md file2.mdThis prints the merged content to the screen instead of saving to a file.
# Convert all meeting PDFs to Markdown
python mdg.py convert ~/Documents/meetings -o ~/Documents/meetings-md
# Merge them into one file
python mdg.py merge ~/Documents/meetings-md -o ~/Documents/all-meetings.md# Convert the contract
python mdg.py convert ~/Downloads/contract.pdf -o ~/Desktop/contract.md
# Open it in your text editor
open ~/Desktop/contract.md# Convert all quarterly reports
python mdg.py convert ~/Documents/reports -o ~/Documents/reports-md
# Merge them chronologically
python mdg.py merge ~/Documents/reports-md/Q1.md ~/Documents/reports-md/Q2.md ~/Documents/reports-md/Q3.md ~/Documents/reports-md/Q4.md -o ~/Documents/annual-report.mdWhen you convert a document, the tool:
- Preserves headings, lists, and tables
- Extracts text content
- Maintains document structure
- Saves as clean Markdown
When you merge files, the tool:
- Adds a comment showing the source filename:
<!-- source: filename.md --> - Separates each file with a horizontal rule:
--- - Preserves all original content exactly
Example merged output:
<!-- source: chapter1.md -->
# Chapter 1
Content here...
---
<!-- source: chapter2.md -->
# Chapter 2
More content...Make sure you've activated the virtual environment:
source .venv/bin/activateThe dependencies aren't installed. Reinstall them:
source .venv/bin/activate
pip install -r requirements.txtThe tool only supports .pdf, .docx, and .doc files. Other formats (like .pptx, .xlsx) are not currently supported.
The folder you specified doesn't contain any PDF or DOCX files. Check the path and try again.
Some PDFs (especially scanned documents or image-based PDFs) may not convert well. This tool uses text extraction, not OCR. For scanned documents, you'd need a different approach.
- Always activate the virtual environment before running commands
- Use absolute paths (starting with
/or~) to avoid confusion - Batch convert folders instead of individual files when possible
- Check the output after conversion - complex documents may need manual cleanup
- Merge in order - files are merged in the order you specify them
| Task | Command |
|---|---|
| Convert one PDF | python mdg.py convert file.pdf |
| Convert one DOCX | python mdg.py convert file.docx |
| Convert with custom output | python mdg.py convert file.pdf -o output.md |
| Convert entire folder | python mdg.py convert /path/to/folder |
| Merge specific files | python mdg.py merge a.md b.md -o combined.md |
| Merge folder contents | python mdg.py merge /path/to/folder -o combined.md |
| Get help | python mdg.py --help |
Run the help command to see all options:
python mdg.py --help
python mdg.py convert --help
python mdg.py merge --help