LoginSignup
87
91

More than 3 years have passed since last update.

MarkdownをPDFに変換する方法

Last updated at Posted at 2017-01-27

目的

Markdownで書かれた文章を印刷したいです。

  • Markdownそのままを印刷すると読みにくい
  • htmlに変換して印刷しても読みにくい

この問題を解決します。

手段

Chrome拡張 Markdown Preview Plus

Markdown Preview Plus - Chrome ウェブストアをインストールします。ChromeにMarkdownファイルをドラッグアンドドロップしてPDFに変換できます。

もらったMarkdownを変換して見た目を確認したい時に、手軽に変換できて便利です。

Node.jsのツール markdown-pdf

npm -g install markdown-pdf

npmの代わりにyarnを使うと、なんと14秒でインストールできます。

markdown-pdf test.md

で実行ディレクトリに、test.pdfが生成できます。

どうもRemarkableで一度htmlに変換してから、PhantomJSを使ってPDFに変換しているようです。

警告

Nodeの7系だと

(node:19145) DeprecationWarning: Calling an asynchronous function without callback is deprecated.
(node:19145) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 2 end listeners added. Use emitter.setMaxListeners() to increase limit
(node:19145) DeprecationWarning: Calling an asynchronous function without callback is deprecated.
(node:19145) DeprecationWarning: Calling an asynchronous function without callback is deprecated.
(node:19145) DeprecationWarning: Calling an asynchronous function without callback is deprecated.

6系だと

(node:19234) Warning: Possible EventEmitter memory leak detected. 2 end listeners added. Use emitter.setMaxListeners() to increase limit

4または5系だと

(node) warning: possible EventEmitter memory leak detected. 2 end listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at SeriesStream.addListener (events.js:252:17)
    at SeriesStream.Readable.on (_stream_readable.js:673:33)
    at SeriesStream.on (/Users/shigerunakajima/.config/yarn/global/node_modules/series-stream/index.js:12:38)
    at SeriesStream.once (events.js:278:8)
    at SeriesStream.Readable.pipe (_stream_readable.js:486:9)
    at SeriesStream.pipe (/Users/shigerunakajima/.config/yarn/global/node_modules/series-stream/index.js:22:30)
    at /Users/shigerunakajima/.config/yarn/global/node_modules/stream-from-to/index.js:101:25
    at /Users/shigerunakajima/.config/yarn/global/node_modules/mkdirp/index.js:48:26
    at FSReqWrap.oncomplete (fs.js:82:15)

警告が出ます。動くので気にしないで使いましょう。

ダメだった方法

pandocを使ってWordに変換するのは、本当に体裁が残念です。
特にテーブルに対応していないのが悲しいです。

参考

87
91
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
87
91