I have a pdf document with an even number of pages, say 2n, and I would like to split it into n documents, say pages1_2.pdf, pages3_4.pdf, ....., pages2n-1_2n.pdf, each of which consists of 2 successive pages. More precisely, for any i in the interval {1..2n}, the i-th file should consist of page 2i-1 and page 2i of the original document.

pdftk does not seem to have a dedicated function but a for loop could achieve this.

Could you please help me in writing the right script? Thank you in advance

1 Answer 1


First obtain the number of pages in the document:

TOTAL=`pdftk file.pdf dump_data | grep NumberOfPages | awk '{print $2}'` 

Check the result with

echo $TOTAL

Now let's insert that into a loop where we loop from 1 to $TOTAL, skipping 1 each time. Each time around the loop, we will get the i-th and the i-th plus one pages and put them into a file.

for i in `seq 1 2 $TOTAL`
echo "pdftk source.pdf cat $i-$j output output_$i-$j.pdf"
  • Thank you very much! Dec 7, 2020 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .