Your Markdown to PDF/HTML converter with beautiful Mermaid diagram rendering
A powerful and easy-to-use CLI tool for converting Markdown documents to HTML and PDF with full Mermaid diagram support. Perfect for technical documentation, specifications, and reports.
-
π Full Mermaid.js Support - All diagram types render beautifully:
- Flowcharts
- Sequence diagrams
- Gantt charts
- Class diagrams
- State diagrams
- Entity Relationship diagrams
- And more!
-
π¨ Professional Styling
- Clean, readable typography
- Syntax-highlighted code blocks
- Responsive tables
- Dark mode support
- Print-optimized layouts
-
π Easy to Use
- Simple unified CLI command
- Programmatic API
- Sensible defaults
- Highly configurable
-
π Multiple Output Formats
- HTML with interactive features
- PDF with rendered diagrams
- Direct Markdown β PDF conversion
npm install -g pdfmaidnpm install pdfmaid- Node.js 14.0.0 or higher
- Google Chrome or Chromium (for PDF generation)
# Convert Markdown to PDF (default)
pdfmaid document.md
# Convert Markdown to HTML
pdfmaid document.md -o html
# Specify output file
pdfmaid document.md -o report.pdf# Technical documentation with dark theme
pdfmaid api-spec.md -t "API Specification" --theme dark
# Complex diagrams (increase wait time)
pdfmaid architecture.md -w 5000
# Keep HTML for debugging
pdfmaid document.md --keep-html
# Convert existing HTML to PDF
pdfmaid document.html -o pdf
# Landscape orientation
pdfmaid slides.md --landscapeconst { convertMarkdownFile, htmlToPdf } = require('pdfmaid');
// Convert Markdown to HTML
convertMarkdownFile('input.md', 'output.html', {
title: 'My Document',
theme: 'dark',
});
// Convert HTML to PDF
htmlToPdf('output.html', 'output.pdf', {
waitTime: 2000,
});pdfmaid <input> [options]<input>- Input file (.md, .markdown, .html, .htm)
| Option | Description | Default |
|---|---|---|
-o, --output <format|file> |
Output format ('pdf' or 'html') or file path | |
-f, --format <format> |
Output format ('pdf' or 'html') | |
-t, --title <text> |
Set document title | derived from filename |
--theme <name> |
Theme: 'default' or 'dark' | default |
-w, --wait <ms> |
Wait time for Mermaid rendering | 2000 |
--landscape |
Use landscape orientation for PDF | false |
--keep-html |
Keep intermediate HTML file | false |
--no-interactive |
Disable interactive features | false |
--chrome <path> |
Path to Chrome/Chromium executable | auto-detect |
-h, --help |
Show help message | - |
-v, --version |
Show version number | - |
pdfmaid document.md
# Creates document.pdfpdfmaid document.md -o html
# Creates document.html with interactive featurespdfmaid document.md -t "Technical Specification" --theme dark
# Creates document.pdf with dark themepdfmaid architecture.md -w 5000
# Waits 5 seconds for complex Mermaid diagrams to renderpdfmaid document.md --keep-html
# Creates both document.pdf and document.htmlpdfmaid document.html -o pdf
# Creates document.pdf from existing HTMLpdfmaid slides.md --landscape
# Creates landscape-oriented PDFpdfmaid input.md -o /path/to/output.pdf
# Creates PDF at specified locationConvert Markdown string to HTML string.
Parameters:
markdown(string): Markdown contentoptions(object):title(string): Document titletheme(string): 'default' or 'dark'includeStyles(boolean): Include built-in styles (default: true)includePrintButton(boolean): Include print button (default: true)
Returns: HTML string
const { markdownToHtml } = require('pdfmaid');
const html = markdownToHtml('# Hello\n\n```mermaid\ngraph TD\nA-->B\n```', {
title: 'My Document',
theme: 'default',
});Convert Markdown file to HTML file.
Parameters:
inputPath(string): Path to input .md fileoutputPath(string): Path to output .html fileoptions(object): Same asmarkdownToHtml
Returns: Output file path
const { convertMarkdownFile } = require('pdfmaid');
convertMarkdownFile('input.md', 'output.html', {
title: 'My Document',
theme: 'dark',
});Convert HTML file to PDF.
Parameters:
inputPath(string): Path to input .html fileoutputPath(string): Path to output .pdf fileoptions(object):chromePath(string): Path to Chrome executablewaitTime(number): Wait time in ms (default: 2000)landscape(boolean): Use landscape orientation
Returns: Output file path
const { htmlToPdf } = require('pdfmaid');
htmlToPdf('input.html', 'output.pdf', {
waitTime: 3000,
landscape: false,
});Find Chrome/Chromium executable on the system.
Returns: Path to Chrome or null if not found
const { findChrome } = require('pdfmaid');
const chromePath = findChrome();
console.log(chromePath); // e.g., '/usr/bin/google-chrome'Full support for:
- Tables
- Task lists
- Strikethrough
- Autolinks
- And more!
All Mermaid diagram types are supported:
```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Success]
B -->|No| D[Retry]
D --> B
``````mermaid
sequenceDiagram
Alice->>John: Hello John!
John-->>Alice: Hi Alice!
```Syntax highlighting for all common languages:
```javascript
function hello() {
console.log('Hello, world!');
}
```Clean, professional light theme perfect for documentation.
pdfmaid document.md --theme defaultEye-friendly dark theme with syntax highlighting.
pdfmaid document.md --theme darkIf you get a "Chrome not found" error:
-
Install Chrome or Chromium:
# Ubuntu/Debian sudo apt install chromium-browser # Fedora sudo dnf install chromium # macOS brew install --cask google-chrome
-
Or set CHROME_PATH:
export CHROME_PATH=/path/to/chrome pdfmaid document.md -
Or specify chrome path in command:
pdfmaid document.md --chrome /path/to/chrome
If diagrams appear as code instead of rendered:
-
Increase wait time:
pdfmaid document.md -w 5000
-
Verify syntax:
- Check your Mermaid syntax at mermaid.live
For large documents with many complex diagrams:
pdfmaid document.md -w 10000pdfmaid technical-spec.md -o spec.pdf -t "API Technical Specification"pdfmaid architecture.md --keep-html -w 3000pdfmaid report.md -t "Quarterly Report" --theme darkContributions are welcome! Please feel free to submit a Pull Request.
MIT Β© Lyuboslav Petrov
- Mermaid.js - Diagram rendering
- Marked - Markdown parsing
- Chrome/Chromium - PDF generation
Made with β€οΈ by Lyuboslav Petrov