Is there an easy (preferably command line) way to reverse the pages in a PDF file?


PDFtk can also do this (it’s available in most distributions as pdftk):

pdftk myfile.pdf cat end-1 output myfilereversed.pdf
  • It's not available on Arch Linux (only via AUR) and there might be a good reason for that. Anyway, in that case, pdfjam is a good alternative.
    – user905686
    Apr 25 '18 at 14:03
  • @user905686 agreed, I’m presenting this as an alternative, not saying using pdfjam is wrong ;-). Apr 25 '18 at 14:04
  • It works on macOS too - in case anyone reaches this page from a Google search.
    – tvk
    Apr 25 at 19:54

One can make use of pdfjam which provides a front end to the "pdfpages" LaTeX package (and thus comes for example with texlive).

It generally allows to create a new PDF file by selecting pages from multiple PDF files. Particularly it allows to specify decending ranges, using "last" to refer to the last page:

pdfjam myfile.pdf 'last-1' --outfile myfilereversed.pdf

reverses myfile.pdf.

For further possibilities see pdfjam --help and the documentation of pdfpages.


You can use qpdf:

qpdf --empty --pages infile.pdf z-1 -- outfile.pdf

You can find more information here on page 11.

  • 1
    Of all the answers so far, this was the lightest, easiest install (brew install qpdf) on macOS 10.13.6. Also it's very fast. Dec 10 '19 at 10:23
  1. From the Gist:
brew install https://raw.githubusercontent.com/turforlag/homebrew-cervezas/master/pdftk.rb
  1. In your ~/.bashrc, put this:
function pdfreverse {
  /usr/local/bin/pdftk "$1" cat end-1 output ${OUTPUT}
  /bin/rm "$1"
  /bin/mv ${OUTPUT} "$1"

Make a new Terminal window. Then run :

pdfreverse sample.pdf

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.