wkhtmltopdfはその名の通り、Webkitのレンダリングエンジンを用いて、HTMLをPDFに変換するというソフトウェアです。
ちょっとしたドキュメントを作る際に、慣れしたんだHTML+CSSでPDFを作れるとやっぱり楽ですね。
俺達はWordやExcelなんて使いたくないんだ。
環境
ubuntu 12.04でのお話です。
でもWinやMac用のものもあるので適宜置き換えてください。
インストール
wget https://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2 tar xvf wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2 cp wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
ubuntuとかならapt-getでもインストールできますが、この場合QTが使われるのでGUI環境が必要なります。
サーバーとして使ってる場合、そんなの入れたくないので上の方法のほうがいいと思います。
使い方
シンプルに使うにはこんな感じです。
wkhtmltopdf input.html output.pdf
WebページのもPDFにできます。
wkhtmltopdf http://example.com/hoge.html output.pdf
その他こんなにたくさんオプションあります
Global Options:
--collate Collate when printing multiple copies
(default)
--no-collate Do not collate when printing multiple
copies
--copies <number> Number of copies to print into the pdf
file (default 1)
-H, --extended-help Display more extensive help, detailing
less common command switches
-g, --grayscale PDF will be generated in grayscale
-h, --help Display help
-l, --lowquality Generates lower quality pdf/ps. Useful to
shrink the result document space
-O, --orientation <orientation> Set orientation to Landscape or Portrait
(default Portrait)
-s, --page-size <Size> Set paper size to: A4, Letter, etc.
(default A4)
-q, --quiet Be less verbose
--read-args-from-stdin Read command line arguments from stdin
--title <text> The title of the generated pdf file (The
title of the first document is used if not
specified)
-V, --version Output version information an exit