Created
February 18, 2021 16:34
-
-
Save ThomasG77/0a04ef4aae660292ca5e8486df576b2d to your computer and use it in GitHub Desktop.
Need to split PDF every n pages, do it with 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
# 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