md2pdf converts Markdown files to A4 PDF files. It uses Chrome or Chromium to print the PDF.
You need these items:
- A C compiler (
ccorgcc) - libcmark-gfm development files
- Google Chrome or Chromium
On Arch Linux, install libcmark-gfm:
sudo pacman -S cmark-gfmOn Debian or Ubuntu, install libcmark-gfm development files:
sudo apt install libcmark-gfm-devRun this command in the repository root:
makeThe build creates the md2pdf binary (about 26 KB). It embeds default.css and default.html in the binary.
Edit default.css to change default typography, tables, headers, and print layout.
Edit default.html to change the HTML shell. Use these placeholders:
| Placeholder | Value |
|---|---|
{{TITLE}} |
Document title |
{{HTML_ATTRS}} |
Extra attributes on <html> (e.g. page-number class) |
{{DEFAULT_CSS}} |
Embedded CSS from default.css |
{{EXTRA_CSS}} |
CSS from --stylesheet |
{{HEADER}} |
Header HTML from front matter |
{{DOC_CLASS}} |
doc or doc has-chrome |
{{BODY}} |
Rendered Markdown |
{{FOOTER}} |
Footer HTML from front matter |
Run make again after you change default.css or default.html.
Install the binary to /usr/local/bin:
make installTo install to /usr/bin, run:
make install PREFIX=/usr./md2pdf INPUT.md
./md2pdf INPUT.md OUTPUT.pdf
./md2pdf --stylesheet cv.css INPUT
./md2pdf -s proposal.css notes.md out/proposal.pdf
./md2pdf --template custom.html INPUT.md
./md2pdf -t custom.html -s cv.css INPUT.mdINPUT can omit the .md extension. The tool checks these names in order:
INPUTINPUT.mdINPUT.markdown
If you omit OUTPUT, the tool writes INPUT.pdf in the same directory as the input file.
If OUTPUT has no .pdf extension, the tool adds .pdf.
Show command help:
./md2pdf --helpPut YAML front matter at the top of the Markdown file:
---
company: Example Ltd
client: Acme Corp
subtitle: Custom line under the company name
logo: assets/logo.svg
date: 2026-09-03
reference: DOC-001
footer: hello@example.com · +1 555 0100
email: hello@example.com
phone: +1 555 0100
website: https://example.com
footer-pages: true
---| Field | Purpose |
|---|---|
title |
Document title. It replaces the first # heading. |
logo |
Image path. The path is relative to the Markdown file. |
company |
Main header line on the left |
client |
Left header subtitle as Proposal for … |
subtitle |
Left header subtitle as free text. It replaces client. |
date |
Right header line |
reference |
Right header line |
footer |
Left footer text |
email |
Footer text when footer is empty |
phone |
Footer text when footer is empty |
website |
Footer text when footer is empty |
footer-pages |
Page numbers on the right (1 / 4) |
The tool joins email, phone, and website with · when footer is empty.
Use proposal.css or your own stylesheet to style .doc-header and .doc-footer.
The build compiles default.css into the binary. That file sets default typography and layout.
The build compiles default.html into the binary. That file sets the HTML document structure.
Use --stylesheet or -s to add CSS after the defaults.
Use --template or -t to replace the built-in HTML shell with your own file. The file must use the same placeholders as default.html (see above).
Put this HTML comment on its own line before a section that must start on a new page:
<!-- pagebreak -->These variants also work: page-break, page break.
The tool searches for these program names on PATH:
google-chromegoogle-chrome-stablechromiumchromium-browser
Set MD2PDF_CHROME when the browser is not on PATH:
MD2PDF_CHROME=/path/to/chromium ./md2pdf INPUT.mdYou can also pass --chrome /path/to/chromium.
This project uses the MIT License. See LICENSE.