home / skills / steveclarke / dotfiles / md-to-pdf

md-to-pdf skill

/ai/skills/md-to-pdf

This skill converts markdown to PDF using Chrome, enabling diagrams, math, and syntax highlighting for shareable, print-ready documents.

npx playbooks add skill steveclarke/dotfiles --skill md-to-pdf

Review the files below or copy the command above to add this skill to your agents.

Files (5)
SKILL.md
2.8 KB
---
name: md-to-pdf
description: Convert markdown files to PDF using Chrome. Use when user wants to render markdown to PDF, print a document, or create a shareable PDF from markdown. Triggers on "markdown to pdf", "render to pdf", "pdf from markdown", "print this markdown".
---

# Markdown to PDF

Converts markdown files to beautifully formatted PDFs using crossnote (same engine as mcp-printer).

## Features

- **Mermaid diagrams** — Flowcharts, sequence diagrams, etc.
- **Math equations** — KaTeX rendering
- **Syntax highlighting** — GitHub theme
- **Page numbers** — Automatic footer with page X / Y
- **GitHub-light theme** — Clean, print-optimized styling

## Usage

```bash
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md              # Creates input.pdf
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md output.pdf   # Custom output name
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md --open       # Open after creating
```

## Options

| Flag | Description |
|------|-------------|
| `--open`, `-O` | Open the PDF after creating |
| `-o FILE` | Specify output filename |

## Requirements

- **Chrome or Chromium** — Auto-detected on macOS/Linux
- **Node.js** — For running the script
- **Dependencies** — Run `npm install` in the skill directory once

## How It Works

1. Uses **crossnote** (Markdown Preview Enhanced engine)
2. Injects page numbering config into front-matter
3. Renders via Chrome/Puppeteer
4. Supports Mermaid, math, code highlighting out of the box

## Examples

```bash
# Quick conversion
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs README.md

# Spec document for sharing
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs spec.md spec-v2.pdf --open

# Multiple files
for f in docs/*.md; do ~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs "$f"; done
```

## Mermaid Example

Include in your markdown:

~~~markdown
```mermaid
graph TD
    A[Start] --> B{Decision}
    B -->|Yes| C[Do something]
    B -->|No| D[Do something else]
```
~~~

The diagram will render as a graphic in the PDF.

## Printing

If the user wants to print the PDF, use the `/print` skill after generating.

**Workflow decision:**

| User intent | Action |
|-------------|--------|
| "Convert to PDF" | Keep the PDF |
| "Print this markdown" | Generate PDF → print with `/print` → delete PDF |
| "Create a PDF and print it" | Keep the PDF, also print |

When printing is the goal (not the PDF itself), delete the PDF after printing:

```bash
# Generate, print, cleanup
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs doc.md
~/.claude/skills/print/scripts/print doc.pdf
rm doc.pdf
```

The `/print` skill handles double-sided and b&w defaults automatically.

## Alias (Optional)

Add to your shell profile:
```bash
alias md-to-pdf='~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs'
```

Overview

This skill converts Markdown files into polished, print-ready PDFs using a headless Chrome renderer. It preserves diagrams, math, and syntax highlighting and adds automatic page numbers and a clean GitHub-light print style. Use it when you need a shareable PDF or a document ready for printing.

How this skill works

The script preprocesses the Markdown, injects page-numbering front-matter, and renders HTML with the crossnote engine. It launches Chrome/Chromium via Puppeteer to produce a high-fidelity PDF that includes Mermaid diagrams, KaTeX math, and GitHub-themed code highlighting. Optional flags let the tool open the PDF after creation or specify an output filename.

When to use it

  • Generate a shareable PDF from a README, spec, or notes
  • Create print-ready documents with page numbers and consistent styling
  • Render Mermaid diagrams and math equations into static graphics
  • Batch-convert multiple Markdown files for distribution
  • Quickly convert a draft to PDF before sending or archiving

Best practices

  • Install Node.js and run npm install in the skill directory once to fetch dependencies
  • Keep Chrome or Chromium installed and up to date for reliable rendering
  • Add front-matter for custom layout or metadata when needed
  • Use the --open flag to preview output immediately and confirm formatting
  • For printing workflows, generate the PDF then invoke your printer skill and remove temporary files if not needed

Example use cases

  • Convert README.md to README.pdf for user documentation distribution
  • Render a spec with diagrams: md-to-pdf spec.md spec-v2.pdf --open
  • Batch-export all docs: for f in docs/*.md; do md-to-pdf "$f"; done
  • Produce a printable handout containing math and code examples
  • Generate a PDF before pushing a release so non-Markdown viewers can read it

FAQ

What are the system requirements?

Chrome or Chromium and Node.js are required. Install dependencies once via npm install in the skill folder.

Can it render diagrams and math?

Yes. Mermaid diagrams and KaTeX math are rendered automatically, and code blocks use GitHub-style highlighting.