Created
July 2, 2012 11:25
-
-
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)
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/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