markdown2pdf converts Markdown to PDF through a fully in-tree pipeline: a CommonMark/GFM lexer, a TOML-driven style resolver, and a layout engine built directly on printpdf. There is no intermediate HTML and no third-party document engine.
It ships as both a binary and a library. The binary converts from a file, URL, or string on the command line; the library exposes programmatic generation with full control over styling and fonts. Configuration is loaded at runtime or embedded at compile time for containerized deployments.
The lexer targets CommonMark 0.31.2 plus GFM and note-tool extensions such as WikiLinks, ==highlight==, and LaTeX math, and passes 649 of the 652 CommonMark spec examples. The exceptions are deliberate, where the WikiLink syntax reclaims [[…]] (which CommonMark treats as nested brackets). Conformance is held in place by the full CommonMark spec runner alongside the lexer-unit, stress, and adversarial renderer suites.
The renderer covers headings with bookmarks and anchors, the full inline-emphasis set (bold, italic, monospace, strikethrough, underline, highlight, super/subscript, small-caps), nested ordered/unordered/task lists, GFM tables with per-column alignment and header repeat, blockquotes, fenced and indented code, images (local, URL, SVG), footnotes, definition lists, cross-references, and inline HTML. Mathematics is typeset by a built-in TeX engine — real fraction bars, radicals, script stacks, big operators with limits, growing delimiters, matrices, and accents — drawn as vector outlines and configurable through a [math] style block.
Documents are styled per block with six bundled themes, configurable page setup, running headers and footers, an auto-generated table of contents, a title page, YAML/TOML frontmatter, and PDF metadata. Output is written to a file or returned as an in-memory byte buffer.
Install binary
Homebrew
Cargo
Install the binary globally using cargo:
For the latest git version:
URL input (-u) and SVG images are behind optional features; pass
them to cargo install (see Feature flags):
Prebuilt binaries
Prebuilt versions are available in our GitHub releases:
| File | Platform | Checksum |
|---|---|---|
| markdown2pdf-aarch64-apple-darwin.tar.xz | Apple Silicon macOS | checksum |
| markdown2pdf-x86_64-apple-darwin.tar.xz | Intel macOS | checksum |
| markdown2pdf-x86_64-pc-windows-msvc.zip | x64 Windows | checksum |
| markdown2pdf-aarch64-unknown-linux-gnu.tar.xz | ARM64 Linux | checksum |
| markdown2pdf-x86_64-unknown-linux-gnu.tar.xz | x64 Linux | checksum |
Install as library
Add the crate to your project:
Or, in Cargo.toml:
# Minimal — local files only, no network, no SVG
= "1.2.0"
# Or with URL fetching + SVG rasterization
= { = "1.2.0", = ["fetch", "svg"] }
See docs/library.md for the programmatic API.
Feature flags
Two optional features, both off by default and shared by the binary
and the library. The library enables them in Cargo.toml
(features = [...]); the binary enables them at install or build
time (cargo install markdown2pdf --features fetch,svg).
fetch— URL input (the-u/--urlflag) and remote images. Uses pure-Rust TLS (rustls), so no system OpenSSL is needed; works inrust:slimand Alpine. If you need native TLS for corporate certificate stores, depend onreqwestdirectly with your preferred backend and Cargo will unify the features.svg— SVG image rasterization viaresvg, for SVG embedded throughor<img src="...svg">.
Configuration
Every visual choice — fonts, colors, page setup, headers / footers,
table of contents, title page, alignment, per-block typography — lives
in a TOML configuration. Six bundled themes (default, github,
academic, minimal, compact, modern) give one-line styling;
per-block overrides handle the long tail; and any value can be
overridden per-run from the command line, winning over the config
file and theme.
# A theme
# Your own config file
# Override individual values at runtime (highest priority)
The full schema with every field explained is in
docs/configuration.md; an annotated,
copy-and-tweak reference config is docs/config.toml.
Usage
The binary converts a file (-p), a string (-s), or a URL (-u,
with the fetch feature) to a PDF (-o, default ./output.pdf).
--dry-run validates input without writing; --print-effective-config
emits the resolved style as TOML; --verbose and --quiet adjust
logging. The complete flag reference, config-override precedence, and
font selection are in docs/cli.md.
Library Usage
parse_into_file writes a PDF to disk; parse_into_bytes returns the
document as a Vec<u8> for in-memory use. ConfigSource selects
styling — Default, Theme("github"), File(path), or
Embedded(toml).
use ;
parse_into_file?;
parse_into_file?;
Pre-resolved styles and runtime overrides, font selection (by name,
path, or embedded bytes), frontmatter, and the error model are
covered in docs/library.md.
Contributing
For information regarding contributions, please refer to CONTRIBUTING.md file.