MD2PDF Converter
Overview
MD2PDF is a self-hosted web utility for writing and converting Markdown documents into beautifully styled PDFs with real-time preview and client-side Mermaid flowchart diagram rendering.
Key Capabilities
- Dual-Pane Editor: Live Markdown text area on the left with instant synchronized preview on the right.
- 7 Thematic Styles: Includes Modern (Default), GitHub, Dracula (Dark), Nord, Solarized Light, Academic (LaTeX serif), and Minimalist Elegant.
- Mermaid.js Flowcharts: Automatically parses ` ```mermaid ` code fences and converts them into SVG flowcharts and sequence diagrams before PDF generation.
- Serverless-Grade Headless Rendering: Utilizes system Chromium via Puppeteer to render exact print-quality CSS page breaks, headers, footers, and margins.
Architecture & Container Configuration
User Browser
│ (Markdown text + Selected Theme + Rendered Mermaid SVGs)
▼
Gateway API (my-gateway) -> md2pdf-route (md2pdf.babdelka.com)
│
▼
Express.js Service (:3000)
│
▼
Puppeteer (Chromium /usr/bin/chromium)
│ (HTML with inline CSS + theme rules)
▼
Generated PDF Stream (application/pdf)
Container Details
- Base Image:
node:20-bookworm-slim - Chromium: System-installed
/usr/bin/chromium(no download overhead) - Init System:
dumb-inithandling PID 1 zombie processes for headless browsers - Memory Shm: Mounted
emptyDirwithmedium: Memory(512Mi) at/dev/shmto prevent Chromium sandbox crashes under concurrency.
API Endpoints
1. POST /api/convert
Renders Markdown or compiled HTML into a downloadable PDF document.
- Request Body (
application/json):{ "markdown": "# Document Title\n\nContent here...", "theme": "academic", "renderedHtml": "<h1 id=\"document-title\">Document Title</h1><p>Content here...</p>", "options": { "format": "A4", "landscape": false, "printBackground": true } } - Response: Binary stream (
application/pdf) withContent-Disposition: attachment; filename="document.pdf".
2. GET /health
Liveness and readiness check. Returns status 200 OK with { "status": "healthy", "uptime": 1234 }.
Operations & Troubleshooting
Viewing Logs
kubectl logs -n md2pdf -l app=md2pdf -f
Restarting the Service
kubectl rollout restart deployment/md2pdf -n md2pdf
Common Issues
- Chromium crash on large diagrams: Check
/dev/shmmemory allocation inapps/src/md2pdf/deployment.yaml. The emptyDir must allow at least 256Mi–512Mi.