Skip to content

Repository files navigation

mdpdf

CI NPM Version

Convert Markdown to PDF with a self-contained Rust binary via CLI or Node.js.

Features

  • Convert Markdown to PDF using Typst
  • Self-contained (no large external dependencies)
  • Cross-platform support (x86_64 and aarch64)
  • Node.js bindings via napi-rs
  • Syntax highlighting for code blocks
  • GitHub Flavored Markdown features, including alerts, footnotes, task lists, tables, and strikethrough
  • Math rendering, internal links, and optional tables of contents
  • Custom fonts, page sizes, margins, and Typst configuration

Example Output

Usage

Basic Usage

CLI

mdpdf README.md -o README.pdf

Node.js

npm install @mdpdf/mdpdf
# or
yarn add @mdpdf/mdpdf
# or
pnpm add @mdpdf/mdpdf
import { markdownToPdf, markdownToPdfWithStats } from "@mdpdf/mdpdf";

const options = {
  pageSize: "a4",
  margin: "20mm",
  fontFamily: "Liberation Serif",
  fontPaths: ["./fonts"],
  fontSize: 11,
  toc: true,
  typstConfig: "#set text(fill: navy)",
};

const pdfBytes = await markdownToPdf("# This is Markdown", options);
const { pdf, stats } = await markdownToPdfWithStats(
  "# This is Markdown",
  options,
);

markdownToPdfWithStats returns the generated PDF and character, line, conversion-time, and rendering-time statistics. markdownToTypstCode accepts the same options. Existing positional Node.js arguments remain supported but are deprecated; pass an options object for new code.

The CLI accepts equivalent document options:

mdpdf document.md --output document.pdf --page-size a4 --margin 20mm \
  --font-size 11 --font-path ./fonts --toc

Development

CLI

cargo build --release --features cli
cargo test

Node.js

corepack yarn install --immutable
corepack yarn build
CI=1 corepack yarn test

This project requires the Yarn version pinned in package.json. Use corepack yarn rather than a globally installed yarn; this avoids falling back to Yarn 1 and ensures failed N-API builds cannot leave index.d.ts empty.

About

Convert Markdown to PDF using a self-contained Rust binary (CLI or Node.js)

Topics

Resources

Stars

20 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages