Insert a blank page between each existing page in a PDF document

tim picture tim · Oct 17, 2012 · Viewed 17.8k times · Source

I've got a PDF and I want a fast way to insert a blank page every second page (except at the end). E.g. my PDF has the pages

1: A
2: B
3: C
4: D

it should look like:

1: A
2: empty
3: B
4: empty
5: C
6: empty
7: D

Is there any easy scripting way to do so? I thought of using pdftk but I don't know exactly if it's the easiest way to do... I'm running Windows 7.

Thanks so far!

Answer

ucyo picture ucyo · Oct 30, 2014

Had also this idea for reviewing paper. Here is the full script.

#!/bin/bash

if [ $# -ne 1 ]
then
  echo "Usage example: ./bashscript src.pdf"
  exit $E_BADARGS
else
  NUM=$(pdftk $1 dump_data | grep 'NumberOfPages' | awk '{split($0,a,": "); print a[2]}')
  COMMSTR=''

  for i in $(seq 1 $NUM);
  do
    COMMSTR="$COMMSTR A$i B1 " 
  done
  $(echo "" | ps2pdf -sPAPERSIZE=a4 - pageblanche.pdf)
  $(pdftk A=$1 B=pageblanche.pdf cat $COMMSTR output 'mod_'$1)
  (pdfnup 'mod_'$1 --nup 2x1 --landscape --outfile 'print_'$1)
  $(rm pageblanche.pdf && rm 'mod_'$1)

fi

#for f in *.pdf; do ./bashscript.sh $f; done 2> /dev/null