md-to-pdf is a CLI tool for converting Markdown files to PDF using Marked (for HTML rendering) and Puppeteer (headless Chromium for PDF generation). Current stable version is 5.2.5 (last updated November 2023). It supports concurrent conversion of multiple files, watch mode, front-matter configuration, custom stylesheets/scripts, headers/footers, page breaks, syntax highlighting via highlight.js, and both CLI and programmatic API. Key differentiators include its hackability (~500 lines of TypeScript), stdio support, and optional HTML output. Note: v5.0.0 disabled JavaScript in front-matter by default to prevent RCE (security fix). Requires Node >=12.
npm install md-to-pdfVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic API: convert a markdown string to PDF with custom PDF options and CSS, then save to file.
To enable JS in front-matter, pass `--gray-matter-options 'null'` on CLI or set `gray_matter_options: undefined` in programmatic options.
Install Puppeteer's missing dependencies as per https://pptr.dev/troubleshooting#chrome-headless-doesnt-launch-on-unix
Use `--body-class` in CLI or `body_class` in programmatic options.
Upgrade to v5.2.4 or later, or set `--md-file-encoding` for certain edge cases.
Pass `highlight` function in `marked_options` instead of custom renderer.
Run `npm install puppeteer` in your project or install globally with `npm i -g puppeteer`.
Install required libraries: e.g., `sudo apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libdbus-1-3 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2`.
Set `gray_matter_options: undefined` in programmatic API or pass `--gray-matter-options 'null'` in CLI to allow JavaScript execution.
Ensure the value is correctly typed: in CLI use JSON string like `--marked-options '{"breaks": true}'`, in programmatic API pass actual boolean.