Markdownのシェアが増えるのに従って、とりあえずメモはMarkdownでしておくという人も多いでしょう。しかし業務で提出する資料や公開資料などはHTMLではなく、PDFベースでの提出を求められることが多いです。 Webブラウザに出して、それをPDFに変換しても良いですが、それならばmarkdown-pdfを使ってみましょう。markdown-pdfはその名の通り、MarkdownファイルをPDFに変換するソフトウェアです。

markdown-pdfの使い方

markdown-pdfはnpmを使ってインストールできます。

npm install -g markdown-pdf

使い方は以下の通りです。

$ markdown-pdf

  Usage: markdown-pdf [options] <markdown -file-path>

  Options:

    -h, --help                             output usage information
    -V, --version                          output the version number
    </markdown><markdown -file-path>                   Path of the markdown file to convert
    -c, --cwd [path]                       Current working directory
    -p, --phantom-path [path]              Path to phantom binary
    -h, --runnings-path [path]             Path to runnings (header, footer)
    -s, --css-path [path]                  Path to custom CSS file
    -z, --highlight-css-path [path]        Path to custom highlight-CSS file
    -f, --paper-format [format]            'A3', 'A4', 'A5', 'Legal', 'Letter' or 'Tabloid'
    -r, --paper-orientation [orientation]  'portrait' or 'landscape'
    -b, --paper-border [measurement]       Supported dimension units are: 'mm', 'cm', 'in', 'px'
    -d, --render-delay [millis]            Delay before rendering the PDF
    -t, --load-timeout [millis]            Timeout before the page is rendered in case `page.onLoadFinished` isn't fired
    -o, --out [path]                       Path of where to save the PDF

CSSをカスタムできるので、体裁はカスタマイズできるようになっています。以下は変換例です。

画像も含めてちゃんとPDFになっています。カスタムのスタイルシートを使えば、自社のロゴを入れたり、フォントを指定すると言ったこともできるでしょう。

markdown-pdfはnode/JavaScript製、MIT Licenseのオープンソース・ソフトウェアです。

alanshaw/markdown-pdf