Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

md2pdf

Pixel-perfect Markdown → PDF.
Preview it in your browser, paginate in A4, then export exactly what you see.

Stop guessing how your PDF will look.
md2pdf opens a real paginated preview, lets you pick a template and font, and generates a WYSIWYG PDF with identical layout.

The missing WYSIWYG Markdown → PDF CLI.


Why md2pdf?

Most Markdown → PDF tools:

  • render differently in the final PDF
  • break pagination
  • require complex Pandoc configs
  • don't support Mermaid/KaTeX properly
  • have no visual template selection

md2pdf fixes that.

👉 What you preview = what you export.


Key Features

  • 🖥️ Browser-based A4 preview with real pagination
  • 👀 Live watch reload — edit your .md in any editor, preview refreshes automatically (scroll position preserved)
  • 🎨 7 templates — Clean · Classic · Modern · Academic · Editorial · Manuscript · Technical
  • 🔤 8 fonts — Fraunces · Instrument Serif · EB Garamond · Jakarta Sans · Figtree · Times · JetBrains Mono · Template Default
  • 📐 Adjustable margins — vertical/horizontal, 5–30 mm
  • 🧭 Document outline drawer with click-to-jump headings
  • 🔍 Page navigator + zoom (Fit · 50 · 75 · 100 · 125 · 150 %)
  • 📊 Word count + reading time
  • 🌀 Terminal spinner during PDF conversion
  • 📐 KaTeX math support
  • 🧩 Mermaid diagrams
  • ☑️ Task lists
  • 🖼️ Relative image auto-resolution
  • 🛡️ Overwrite protection

One-liner

md2pdf file.md

Preview → choose style → export → done.


📋 Requirements

  • Node.js 20+
  • Chromium-based browser (Chrome, Chromium, Edge, or Brave)

On macOS, default browser paths are scanned automatically. If your browser is in a different location, set the CHROME_PATH environment variable.


📦 Installation

Via npm (from GitHub)

npm install -g github:merttcetn/md2pdf

This command installs dependencies, builds the project, and makes the md2pdf command available globally.

Build from source

git clone https://github.com/merttcetn/md2pdf.git
cd md2pdf
npm install   # installs dependencies and builds automatically
npm install -g .

One-line installation (script)

bash installation.sh

If you do not want a global installation:

bash installation.sh --no-global

🔄 Update

If installed via npm

npm update -g md2pdf

If installed from source

cd md2pdf
git pull
npm install
npm install -g .

🚀 Usage

md2pdf file.md
  1. A preview opens in your browser.
  2. Select a template and font.
  3. Set the output PDF path.
  4. Click OK to generate the PDF, or Cancel to exit.

🛠️ Development

npm install        # install dependencies + build
npm run build      # manual build
npm test           # run tests

Project Structure

src/
  cli.ts                 # Express + SSE server + CLI entry point
  main/
    pdf-service.ts       # PDF generation with Playwright (+ margin support)
    path-utils.ts        # File path utilities
    file-watcher.ts      # Debounced fs.watch for live reload
    spinner.ts           # Terminal Braille spinner
  renderer/
    index.html           # Web UI (editorial layout)
    renderer.ts          # Markdown render + pagination + UI wiring
    styles.css           # Editorial theme (cream paper, Fraunces)
    watch-client.ts      # SSE EventSource + scroll preservation
    outline.ts           # Document outline DOM helpers
    page-navigator.ts    # Page nav + zoom controls
    word-count.ts        # Word count + reading time (re-export)
  shared/
    types.ts             # Shared type definitions
    templates.ts         # Template list
    outline-extract.ts   # Pure heading extractor
    word-count-stats.ts  # Pure stats computation
  tests/
    *.test.ts            # node:test unit tests

About

A CLI tool that previews Markdown files in the browser and converts them to PDF.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages