Created
October 5, 2012 13:25
-
-
Save dataich/3839799 to your computer and use it in GitHub Desktop.
HTML slides to PDF by cutycapt and imagemagick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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