MDPDF - Markdown to PDF converter

A command line markdown to pdf converter with support for page headers, footers, and custom stylesheets. Mdpdf is incredibly configurable and has a JavaScript API for more extravogant usage.

For examples of how to use headers and footers, see the examples directory.

If you're using the Atom text editor, checkout the markdown-pdf plugin which uses mdpdf.

Sponsor this project

This project is actively maintained during evenings and weekends. If you or your company find it useful, please consider supporting the project through sponsorship.

Contributions

If you wish to report bugs or contribute fixes and features, please see the contributors guide

Installation

Install globally to use from the command line.

npm install mdpdf -g

Install locally to access the API.

npm install mdpdf --save

Example usage

Options

Length parameters ( and ) require a unit. Valid units are mm , cm , in and px .

Headers and footers

Note: mdpdf pre-2.x made use of Phantom.js which had considerably better support for headers and footers, and including better styling support for them. Sadly Phantom.js is no longer supported and had a number of other rendering bugs meaning it was no longer possible to support it as a core component of mdpdf. If you previously relied on good header and footer support you may wish to stick with 1.x releases until Puppeteer prioritises better header and footer support. Currently headers and footers do work in 2.x+ releases, but their styles must be handled independently of the main markdown file via --styles options and a few css tags do not work correctly. Past this there shouldn't be any issues with 2.x+ headers and footers.

Environment variables

Emoji support

In text emoji's are also supported, but there are a few instances of shorthand which do not work and require the longhand version, i.e. :+1: doesn't work but :thumbsup: will.

Programatic API

The API is very straight forward with a single function convert() which takes some options. The convert method uses a promise. For a full example see the bin/index.js!

Example API usage

const mdpdf = require('mdpdf'); const path = require('path'); let options =  source: path.join(__dirname, 'README.md'), destination: path.join(__dirname, 'output.pdf'), styles: path.join(__dirname, 'md-styles.css'), pdf:  format: 'A4', orientation: 'portrait' > >; mdpdf.convert(options).then((pdfPath) =>  console.log('PDF Path:', pdfPath); >).catch((err) =>  console.error(err); >);

Options