Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save btbytes/ee42eca552b8779a9305afe4d909651f to your computer and use it in GitHub Desktop.
Save btbytes/ee42eca552b8779a9305afe4d909651f to your computer and use it in GitHub Desktop.
Need to split PDF every n pages, do it with pdftk
# Recipe from https://unix.stackexchange.com/questions/66931/split-pdf-into-documents-with-several-pages-each
pagesper=2
file=layout_atlas_multipage.pdf
number=$(pdfinfo -- "$file" 2> /dev/null | awk '$1 == "Pages:" {print $2}')
count=$((number / pagesper))
filename=${file%.pdf}
counter=0
while [ "$count" -gt "$counter" ]; do
start=$((counter*pagesper + 1));
end=$((start + pagesper - 1));
counterstring=$(printf %04d "$counter")
pdftk "$file" cat "${start}-${end}" output "${filename}_${counterstring}.pdf"
counter=$((counter + 1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment