Created
March 10, 2024 19:48
-
-
Save dBenedek/f38879817afe894db6ab18224e153719 to your computer and use it in GitHub Desktop.
Split PDF to multiple PDFs by a user-specifid page range
This file contains hidden or 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 | |
############################################################################### | |
# Split PDF to the preferred PDFs by the specified pages # | |
############################################################################### | |
# Benedek Danko | |
# Variables: | |
input_file="$1" | |
increment="$2" | |
max_page_num=$(pdftk "$1" dump_data | grep NumberOfPages | awk '{print $2}') | |
echo "Total number of pages:" $max_page_num | |
max_page_num=$(expr $max_page_num - $increment) | |
echo "Number of pages per output file(s):" $increment | |
for i in $(seq 1 $increment $max_page_num); | |
do | |
num_first=$i | |
num_second="$(expr $i + $increment - 1)" | |
idx=$(expr $num_second / $increment) | |
pdftk "$input_file" cat "$num_first"-"$num_second" output out$idx.pdf | |
done | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example run: