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 '19 at 17:03

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
set -- piece*.pdf
while (($#)); do
  if [ $# -ge 2 ]; then
    reordered+=("$2" "$1")
    shift 2
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

| improve this answer | |
  • 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 '19 at 8:14
  • Thank you, Don! this would work for other file types like DjVu, too! very elegant. – Maxim Oct 31 '19 at 18:56

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.