LoginSignup
29
28

More than 5 years have passed since last update.

wkhtmltopdfでテキストとhtmlをPDFに変換する

Last updated at Posted at 2015-09-24

インストール

sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm
# インストールしないと「error: Failed dependencies」
sudo yum install xorg-x11-fonts-75dpi.noarch
sudo rpm -ivh wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

ローカルのhtmlファイルを変換

wkhtmltopdf input.html output.pdf

ローカルのtextファイルを変換

wkhtmltopdf input.txt output.pdf

URLを指定して変換

wkhtmltopdf http://google.com google.pdf

URLを指定して変換(proxy指定)

wkhtmltopdf --proxy http://user:password@proxyhost.com https://www.google.com google.pdf

文字コードを指定(--encoding)

wkhtmltopdf --encoding shift_jis input.txt output.pdf

用紙サイズ(--page-size)と向き(--orientation)を指定

wkhtmltopdf --page-size A3 --orientation landscape input.txt output.pdf

フォントサイズ(--minimum-font-size)を指定

wkhtmltopdf --minimum-font-size 30 input.txt output.pdf
  • minimumはあるけどmaxは無い模様

印刷CSSを使用(--print-media-type)

wkhtmltopdf --print-media-type http://google.com google_print.pdf

javascriptを無効(--disable-javascript)

wkhtmltopdf --disable-javascript http://google.com google.pdf
29
28
0

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
29
28