28

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

4 Answers4

35

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

pdftk myfile.pdf cat end-1 output myfilereversed.pdf
Stephen Kitt
  • 434,908
  • 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 ;-). – Stephen Kitt Apr 25 '18 at 14:04
  • It works on macOS too - in case anyone reaches this page from a Google search. – tvk Apr 25 '21 at 19:54
11

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.

8

You can use qpdf:

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

You can find more information here on page 11.

SaTa
  • 181
  • 1
  • 2
0
  1. From the Gist:
brew install https://raw.githubusercontent.com/turforlag/homebrew-cervezas/master/pdftk.rb
  1. In your ~/.bashrc, put this:
function pdfreverse {
  OUTPUT=/tmp/`/usr/bin/uuidgen`.pdf
  /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