Skip to main content

Convert Markdown files to beautifully styled PDFs

Project description

๐Ÿ“„ markd2pdf

Transform your Markdown into beautifully styled PDFs

Python 3.12+ License: MIT Code style: black

Features โ€ข Installation โ€ข Usage โ€ข Themes โ€ข Configuration


โœจ Features

  • ๐ŸŽจ 5 Themes โ€” Professional dark, Dracula, Nord, GitHub Dark, and Minimal Light
  • ๐Ÿ“ Batch Processing โ€” Convert entire directory trees recursively
  • ๐Ÿ–๏ธ Syntax Highlighting โ€” Full code block highlighting powered by Pygments
  • ๐Ÿ“ Rich Markdown โ€” Tables, admonitions, footnotes, TOC, abbreviations, and more
  • โšก Parallel Processing โ€” Multi-threaded conversion for speed
  • ๐ŸŽฏ Single File Mode โ€” Convert individual files or entire directories

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.12+

  • System dependencies for WeasyPrint:

    # Arch / Manjaro
    sudo pacman -S pango gdk-pixbuf2
    
    # Debian / Ubuntu
    sudo apt install libpango-1.0-0 libgdk-pixbuf-2.0-0
    
    # macOS
    brew install pango gdk-pixbuf
    

Install from PyPI

pip install markd2pdf

Or with uv:

uv tool install markd2pdf

Install from Source (Development)

git clone https://github.com/ramcharan/markd2pdf.git
cd markd2pdf
uv sync  # or: pip install -e .

๐Ÿš€ Usage

Quick Start

# Convert a single file
markd2pdf convert README.md ./output

# Convert an entire directory
markd2pdf convert ./docs ./pdf-output

# Use a specific theme
markd2pdf convert ./docs ./output --theme dracula

Commands

Usage: markd2pdf [OPTIONS] COMMAND [ARGS]...

Commands:
  convert   Convert Markdown files to PDFs
  themes    List all available themes

Convert Command

Usage: markd2pdf convert [OPTIONS] INPUT_PATH OUTPUT_DIR

Arguments:
  INPUT_PATH  Markdown file or directory to convert  [required]
  OUTPUT_DIR  Directory to save the generated PDFs   [required]

Options:
  -t, --theme [github_dark|dracula|nord|minimal_light|professional_dark]
              CSS theme to use for styling  [default: github_dark]
  --help      Show this message and exit

Examples

# Convert all markdown files in a directory
markd2pdf convert ~/Documents/notes ~/Documents/pdfs

# Convert with the Nord theme
markd2pdf convert ~/notes ~/pdfs -t nord

# Convert a single file with Dracula theme
markd2pdf convert ./README.md ./output --theme dracula

# List available themes
markd2pdf themes

๐ŸŽจ Themes

Theme Description
github_dark GitHub-inspired dark theme (default)
dracula Dracula color scheme with neon accents
nord Arctic-inspired, easy on the eyes
minimal_light Clean light theme for printing
professional_dark Sophisticated dark with blue accents

Preview themes:

markd2pdf themes
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Theme Name        โ”ƒ Description                          โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ github_dark       โ”‚ GitHub-inspired dark theme (default) โ”‚
โ”‚ dracula           โ”‚ Dracula color scheme with neon       โ”‚
โ”‚ nord              โ”‚ Arctic-inspired, easy on the eyes    โ”‚
โ”‚ minimal_light     โ”‚ Clean light theme for printing       โ”‚
โ”‚ professional_dark โ”‚ Sophisticated dark with blue accents โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โš™๏ธ Configuration

Customizing Themes

All theme stylesheets are in the styles/ directory. To create a custom theme:

  1. Create a new CSS file:

    cp styles/professional_dark.css styles/my_theme.css
    
  2. Edit the theme in main.py:

    class Theme(str, Enum):
        professional_dark = "professional_dark"
        dracula = "dracula"
        minimal_light = "minimal_light"
        nord = "nord"
        github_dark = "github_dark"
        my_theme = "my_theme"  # Add your theme
    
  3. Add a description:

    THEME_DESCRIPTIONS = {
        # ...existing themes...
        Theme.my_theme: "My custom theme description",
    }
    

Markdown Extensions

markd2pdf supports these Markdown extensions out of the box:

Extension Description
tables GitHub-style tables
fenced_code Triple-backtick code blocks
codehilite Syntax highlighting
toc Table of contents with [TOC]
admonition Note/warning/tip blocks
footnotes Footnote references
attr_list HTML attributes on elements
def_list Definition lists
abbr Abbreviations
md_in_html Markdown inside HTML blocks

๐Ÿ› ๏ธ Development

# Clone the repo
git clone https://github.com/yourusername/markd2pdf.git
cd markd2pdf

# Install dev dependencies
uv sync --group dev

# Run linters
uv run black main.py
uv run isort main.py
uv run mypy main.py

# Run pre-commit hooks
uv run pre-commit run --all-files

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


Made with โค๏ธ and Python

โฌ† Back to top

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markd2pdf-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markd2pdf-0.1.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file markd2pdf-0.1.0.tar.gz.

File metadata

  • Download URL: markd2pdf-0.1.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for markd2pdf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d3e2b88b6aac2e32dbfc40e966b55ff497646465124b3e4a2863bbc746e2847f
MD5 1463b8722c74e4084fc3ced04815509c
BLAKE2b-256 28cab37647da14d68731a0496f7cfd0492a8724424490a40e5ef3bf97b68f4dd

See more details on using hashes here.

File details

Details for the file markd2pdf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: markd2pdf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for markd2pdf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e1e37d618008c13bd91c0a4848dbc0af898eaa2c0603698e64ed76e6cc9ff9d
MD5 88e7b56a5988af54ce5b1a1dd21a2128
BLAKE2b-256 4ce27d3c09c646ba4c3fc40d51b98dc7125d7f5ca21a8bb64f1525bbcf897a60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page