@tafaju/md-to-pdf
v1.0.5
Published
Convert Markdown with Mermaid, LaTeX, and PlantUML diagrams to professional print-ready PDFs
Downloads
67
Maintainers
Readme
@tafaju/md-to-pdf
Convert Markdown to professional, print-ready PDFs with built-in support for Mermaid diagrams, LaTeX math, PlantUML diagrams, and syntax-highlighted code blocks.
Install
npm install -g @tafaju/md-to-pdfRequires Node.js >= 18.
Usage
md-to-pdf document.mdThis generates document.pdf in the same directory.
Options
| Option | Description | Default |
|---|---|---|
| -o, --output <path> | Output PDF path | <input>.pdf |
| -f, --format <size> | Page format: A4, Letter, Legal | A4 |
| -m, --margin <mm> | Page margin in mm | 20 |
| --css <path> | Additional CSS file to include | — |
| --no-mermaid | Disable Mermaid rendering | — |
| --no-latex | Disable LaTeX math rendering | — |
| --no-plantuml | Disable PlantUML rendering | — |
| --plantuml-jar <path> | Path to plantuml.jar | — |
| --mermaid-theme <theme> | default, dark, forest, neutral | default |
| -v, --verbose | Verbose logging | — |
Examples
# Basic conversion
md-to-pdf report.md
# Custom output path and Letter format
md-to-pdf report.md -o ~/Desktop/report.pdf -f Letter
# With custom branding CSS
md-to-pdf report.md --css my-brand.css
# Wider margins, no Mermaid
md-to-pdf report.md -m 30 --no-mermaidFeatures
Mermaid Diagrams
Fenced code blocks with the mermaid language are rendered as SVG diagrams:
```mermaid
graph LR
A[Start] --> B[End]
```LaTeX Math
Inline math with $...$ and display math with $$...$$ are rendered via KaTeX:
The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$.PlantUML Diagrams
Fenced code blocks with plantuml or puml are rendered as SVG diagrams (requires plantuml.jar):
```plantuml
@startuml
Alice -> Bob: Hello
@enduml
```Syntax Highlighting
Code blocks are syntax-highlighted using highlight.js with the GitHub theme. Over 180 languages are supported.
Custom CSS
Pass a CSS file with --css to override the default styles. An example brand stylesheet is included at styles/example-brand.css with all customizable properties documented.
Utility classes you can use directly in your Markdown via HTML:
<div class="page-break"></div>— force a page break<div class="no-break">...</div>— keep content on the same page<div class="two-col">...</div>— two-column layout<div class="callout">...</div>— highlighted callout box
Programmatic API
import { convertMarkdownToPdf } from "@tafaju/md-to-pdf";
await convertMarkdownToPdf("document.md", {
output: "output.pdf",
format: "Letter",
margin: 25,
mermaid: true,
latex: true,
css: "brand.css",
});License
MIT
