Skip to content

zabio3/md-to-pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MD to PDF Converter

A lightweight, client-side Markdown to PDF converter. No server required - runs entirely in your browser.

Try it online

Demo

Basic Usage

Write Markdown → See live preview → Export to PDF

Features

  • Real-time Markdown preview
  • PDF export with customizable options
  • Syntax highlighting (highlight.js with multiple themes)
  • Mermaid diagram support (flowcharts, sequence diagrams, etc.)
  • Custom header/footer templates with dynamic values
  • Page breaks support (<!-- pagebreak -->)
  • Paper size selection (A4, Letter, Legal, A3, A5)
  • Paper orientation (Portrait / Landscape)
  • Margin adjustment
  • Font size control
  • Typography improvements (Smartypants)
  • GitHub Flavored Markdown support

Usage

Online

Visit https://zabio3.github.io/md-to-pdf/

Local Development

# Clone the repository
git clone <repo-url>
cd md-to-pdf

# Start a local server (choose one)
npx serve              # Node.js
python3 -m http.server 8080  # Python
php -S localhost:8080  # PHP

# Open in browser
open http://localhost:8080

Page Breaks

Insert page breaks in your Markdown using HTML comments:

# Page 1 Content

<!-- pagebreak -->

# Page 2 Content

Note: --- is rendered as a horizontal rule (standard Markdown behavior).

Syntax Highlighting

Code blocks are automatically syntax highlighted using highlight.js with the GitHub theme.

Mermaid Diagrams

Create diagrams using Mermaid syntax in fenced code blocks:

```mermaid
flowchart TD
    A[Start] --> B{Decision}
    B -->|Yes| C[Process]
    B -->|No| D[End]
```

Supported diagram types:

  • Flowcharts
  • Sequence diagrams
  • Class diagrams
  • State diagrams
  • Entity Relationship diagrams
  • And more (Mermaid documentation)

Mermaid rendering can be toggled on/off in Settings > Advanced Settings > Render Mermaid diagrams.

Custom Header/Footer

Add custom headers and footers to your PDF with dynamic values:

Token Description
{date} Current date
{title} Document title (from first H1)

Example footer template: {title} - {date}

Configure in Settings > Advanced Settings > Header / Footer.

Print Options

Additional PDF options available:

  • Orientation: Portrait or Landscape
  • Background printing: Include background colors in PDF

Keyboard Shortcuts

  • Ctrl/Cmd + S: Export to PDF

Tech Stack

  • Vanilla JavaScript (no frameworks)
  • Marked.js - Markdown parsing
  • highlight.js - Syntax highlighting
  • Mermaid.js - Diagram rendering
  • Native browser print API - PDF generation
  • GitHub Pages - Hosting

Deployment

The site automatically deploys to GitHub Pages when pushing to the main branch via GitHub Actions.

Manual Setup

  1. Go to repository Settings > Pages
  2. Under "Build and deployment", select GitHub Actions as the source
  3. Push to main branch to trigger deployment

License

MIT

About

Lightweight browser-based Markdown to PDF converter with real-time preview, Mermaid diagrams, and custom headers/footers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors