Skip to content

Instantly share code, notes, and snippets.

@bjoseru
Created July 2, 2012 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoseru/3032761 to your computer and use it in GitHub Desktop.
Save bjoseru/3032761 to your computer and use it in GitHub Desktop.
Single-command shell script to split a PDF into single pages (based on PDFTK)
#!/bin/bash
# (c) Bjoern Rueffer 2012
function usagetext()
{
cat<<EOF
Usage: $0 [-d] filename.pdf
Will burst a file into single pages, numbered as filename_##.pdf. If -d
is specified, filename.pdf will be deleted afterwards.
EOF
}
function do_burst()
{
file="$1"
if [ ! -e "$file" ]; then
echo Error: File "$file" does not exist.
exit 1
fi
pdftk "$file" burst output "${file%%.pdf}"_%02d.pdf
}
if [ $# -lt 1 ]; then
usagetext
elif [ $1 = -d ]; then
shift
do_burst "$1" && rm "$1"
else
do_burst "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment