Convert Markdown files to beautifully formatted PDFs or editable Word documents (DOCX) using Pandoc and the Typst typesetting engine.
md2pdf provides cross-platform scripts for converting Markdown documents to PDF or DOCX format. The scripts use Pandoc for Markdown parsing, with Typst as the PDF rendering engine for GitHub-inspired PDF output. DOCX output is handled directly by Pandoc and does not require Typst.
- ✓ Native Unicode and emoji support (✓ ✗ 😀 🎉)
- ✓ Modern typography and layout capabilities
- ✓ Fast compilation times
- ✓ No LaTeX dependencies required
- ✓ Active development and community support
- Cross-platform: Works on Windows (PowerShell), Linux, and macOS (Bash), including ARM64
- Multiple output formats: Export to PDF (GitHub-styled) or DOCX (editable Word document)
- Batch conversion: Process entire directories of Markdown files
- Recursive processing: Scan subdirectories for Markdown files
- GitHub styling: Professional, GitHub-themed PDF output
- Front matter: YAML front matter (
title,author,date) is rendered in the output - Relative assets: Images and includes are resolved relative to the source file
- Auto-install: Built-in Typst installation functionality
- Flexible output: Specify custom output directories
-
Pandoc (v3.2 or higher)
- Universal document converter
- v3.2+ is required for Typst output format support
-
Typst (v0.12.0 recommended)
- Modern typesetting engine
- Can be auto-installed by the scripts
- Pandoc (any recent version)
- Handles Markdown to DOCX conversion directly
- Typst is not required
- PowerShell 7+ (for Windows users preferring cross-platform PowerShell)
- Bash 4+ (pre-installed on most Linux/macOS systems)
# Using Chocolatey
choco install pandoc
# Or using winget
winget install JohnMacFarlane.Pandoc
# Or download installer from https://pandoc.org/installing.html# Using Homebrew
brew install pandoc
# Or using MacPorts
sudo port install pandoc# Ubuntu/Debian
sudo apt-get install pandoc
# Fedora
sudo dnf install pandoc
# Arch Linux
sudo pacman -S pandocWindows (PowerShell):
.\md2pdf.ps1 -InstallTypstLinux/macOS (Bash):
chmod +x md2pdf.sh
./md2pdf.sh --installAfter auto-installation, restart your terminal for PATH changes to take effect.
Windows:
# Using Chocolatey
choco install typst
# Or using winget
winget install Typst.TypstmacOS:
# Using Homebrew
brew install typstLinux:
# Using package manager (if available)
# Ubuntu 23.10+
sudo apt install typst
# Or download from GitHub releases
wget https://github.com/typst/typst/releases/download/v0.12.0/typst-x86_64-unknown-linux-musl.tar.xz
tar -xf typst-x86_64-unknown-linux-musl.tar.xz
sudo mv typst-x86_64-unknown-linux-musl/typst /usr/local/bin/git clone https://github.com/lucasmodrich/md2pdf.git
cd md2pdf.\md2pdf.ps1 -InputPath "README.md".\md2pdf.ps1 -InputPath "README.md" -Format docx.\md2pdf.ps1 -InputPath "./docs".\md2pdf.ps1 -InputPath "./docs" -OutputPath "./output" -Recursive.\md2pdf.ps1 -InputPath "./docs" -Format docx -Recursive.\md2pdf.ps1 -InstallTypstchmod +x md2pdf.sh./md2pdf.sh README.md./md2pdf.sh README.md --format docx./md2pdf.sh ./docs./md2pdf.sh ./docs --output-path ./output --recursive./md2pdf.sh ./docs --output-path ./output --format docx --recursive./md2pdf.sh --install./md2pdf.sh --help| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
-InputPath |
String | Yes* | - | Path to a Markdown file or directory |
-OutputPath |
String | No | ./output |
Directory for output files |
-Format |
String | No | pdf |
Output format: pdf or docx |
-Recursive |
Switch | No | false |
Process subdirectories recursively |
-InstallTypst |
Switch | No | false |
Download and install Typst |
*Not required when using -InstallTypst
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
<input_path> |
Positional | Yes* | - | Path to a Markdown file or directory |
-o, --output-path |
Flag | No | ./output |
Directory for output files |
-f, --format |
Flag | No | pdf |
Output format: pdf or docx |
-r, --recursive |
Flag | No | false |
Process subdirectories recursively |
-i, --install |
Flag | No | false |
Download and install Typst |
-h, --help |
Flag | No | false |
Show help message |
*Not required when using --install
PDFs are rendered with GitHub-style formatting via Typst:
- Typography: Cross-platform font priority list —
Segoe UI/Arial/Helvetica/DejaVu Sans - Monospace:
Consolas/Menlo/DejaVu Sans Mono/Courier New - Headings: Bold with horizontal rules for H1 and H2
- Code blocks: Monospace font with light grey background
- Inline code: Monospace font with light background
- Links: Blue, GitHub-style hyperlinks
- Quotes: Left border with grey text
- Page margins: 2.5cm on all sides
DOCX files are produced directly by Pandoc using its default Word styles. The output is clean and fully editable in Microsoft Word or any compatible application. YAML front matter (title, author, date) is preserved as document metadata.
# Windows
.\md2pdf.ps1 -InputPath "./docs" -Recursive
# Linux/macOS
./md2pdf.sh ./docs -r# Windows
.\md2pdf.ps1 -InputPath "./docs" -Format docx -Recursive
# Linux/macOS
./md2pdf.sh ./docs --format docx --recursive# Windows
.\md2pdf.ps1 -InputPath "project-notes.md" -OutputPath "C:\exports"
# Linux/macOS
./md2pdf.sh project-notes.md --output-path ~/exportsOutput files are saved to ./output by default with the appropriate extension:
output/
├── README.pdf # --format pdf (default)
├── CONTRIBUTING.pdf
└── CHANGELOG.pdf
output/
├── README.docx # --format docx
├── CONTRIBUTING.docx
└── CHANGELOG.docx
- Install Pandoc using the instructions above
- Verify installation:
pandoc --version - Restart your terminal after installation
- Run the script with
-InstallTypstor--installflag - Or manually install Typst from https://github.com/typst/typst/releases
- Restart your terminal after installation
The scripts use a cross-platform font priority list. Typst picks the first font it finds installed on the system:
- Body text: Segoe UI → Arial → Helvetica → DejaVu Sans
- Monospace: Consolas → Menlo → DejaVu Sans Mono → Courier New
At least one font from each list is present on all mainstream operating systems. Font warnings in the output are non-fatal — Typst substitutes the next available font automatically.
chmod +x md2pdf.shImage paths must be relative to the source .md file. The scripts write the intermediate Typst file alongside the source markdown so all relative paths resolve correctly:
The above works as long as images/logo.png exists next to the Markdown file.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUsermd2pdf/
├── md2pdf.ps1 # PowerShell script for Windows
├── md2pdf.sh # Bash script for Linux/macOS
├── README.md # This file
├── LICENSE # Project licence
├── input/ # Place source Markdown files here
└── output/ # Generated PDFs saved here by default
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
This project is licensed under the terms specified in the LICENSE file.
- Pandoc - Universal document converter by John MacFarlane
- Typst - Modern typesetting system
- GitHub for design inspiration
- pandoc - Universal markup converter
- typst - A new markup-based typesetting system
- markdown-pdf - VS Code extension for Markdown to PDF
Made with ❤️ for the Markdown community