Skip to content

Instantly share code, notes, and snippets.

@hupili
Created December 3, 2015 15:39
Show Gist options
  • Save hupili/0c241b6a3a6f6e9515e4 to your computer and use it in GitHub Desktop.
Save hupili/0c241b6a3a6f6e9515e4 to your computer and use it in GitHub Desktop.
Turn a PDF into a series of images
#!/bin/bash
if [[ $# == 1 ]]; then
fn_input=$1
else
echo "usage: $0 <fn_input>"
exit 255
fi
rm -rf tmp
mkdir -p tmp
fn_output="${fn_input}.img.pdf"
cd tmp
rm -f *.jpg *.png *.png.pdf
cd -
rm -f $fn_output
convert -depth 8 -density 256 -quality 100 $fn_input -resize 100% tmp/${fn_input}.tmp.%03d.png
cd tmp
ls -1 *.png | xargs -I{} convert {} {}.pdf
pdftk *.png.pdf cat output $fn_output
cd -
cp tmp/$fn_output ./
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment