Created
June 15, 2020 12:55
-
-
Save lincetto/61df4a218456a8619208e4f50cb8b43e to your computer and use it in GitHub Desktop.
Split multiple PDF files in linux using qpdf
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 | |
function process() { | |
echo "Processing $file" | |
totpages=`qpdf --show-npages "$file"` | |
echo "Processing $file : tot pages -> $totpages" | |
numsplit=$((totpages/2)) | |
echo "Processing $file : tot splitted files -> $numsplit" | |
for currsplit in $(seq 1 $numsplit); | |
do | |
echo "Exporting pages $(((currsplit-1)*2+1))-$((currsplit*2)) from $file" | |
qpdf "$file" --pages "$file" $(((currsplit-1)*2+1))-$((currsplit*2)) -- ./OUTPUT/"${file%.*}"-$(((currsplit-1)*2+1))-$((currsplit*2)).pdf | |
done | |
} | |
find . -type f -name "*.pdf" -print0 | while IFS= read -r -d '' file; | |
do | |
process $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment