Skip to content

Instantly share code, notes, and snippets.

@dataich
Created October 5, 2012 13:25
Show Gist options
  • Save dataich/3839799 to your computer and use it in GitHub Desktop.
Save dataich/3839799 to your computer and use it in GitHub Desktop.
HTML slides to PDF by cutycapt and imagemagick
#! /bin/sh
filename="slide.pdf"
if [ $# -ne 2 ]; then
echo "Usage: ./hslide2pdf.sh url maxpage"
exit 1
fi
if [ ! -d tmp ] ; then
mkdir tmp
fi
for i in `seq 1 1 $2`
do
# 指定URLをキャプチャ
# スライドの種類によっては--delayを入れてあげないと、anchorに達する前にキャプチャされて全部一枚目になったりする
CutyCapt --url="$1$i" --delay=2000 --out=tmp/$i.png
# 実際キャプチャされる際、前後のページも入ってくるので、中央部分をクロッピング
# -cropに渡しているサイズは、スライドの実際のコンテンツ部分のサイズに合わせる
convert -gravity center -crop 900x700+0+0 +repage tmp/$i.png tmp/${i}_croped.png
done
# convertする際に*.croped.pngでインプットを渡すと、順番が1,10,2みたいにおかしくなるので
# 一旦更新日でファイル名を取得する
files=`ls -tr \`find tmp -name "*croped.png" -type f -print\``
# 複数のpngを1つのPDFに変換
convert $files -units PixelsPerInch -density 120x120 $filename
open $filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment