1

I have a pdf and I am in need to replace even and odd pages. If I want to be more specific, I must replace (2n-1) page numbers with (2n) ones (1-->2, 2-->1, 3-->4, 4-->3, and the like). How should I do that?

Is there any other free software that can do this job for me?

  • 1
    My bad! It seems that pdftk is not a free software! – Mehdi Abbassi Jan 25 at 17:03
0

With poppler-utils tools you could extract the pages to separate files, reorder & save them into an array and join the elements of that array to produce a new document:

pdfseparate original.pdf piece-%04d.pdf
reordered=()
set -- piece*.pdf
while (($#)); do
  if [ $# -ge 2 ]; then
    reordered+=("$2" "$1")
    shift 2
  else
    reordered+=("$1")
    shift
  fi
done
pdfunite "${reordered[@]}" final.pdf
rm -f piece-*.pdf
unset reordered

If your document has more than 9999 pages adjust the format specifier e.g. %05d

  • Thank you so much! It worked! I entered what you wrote line-by-line and cared about indentations and it worked nice and tidy! :D – Mehdi Abbassi Feb 1 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.