Is there an easy (preferably command line) way to reverse the pages in a PDF file?
Asked
Active
Viewed 9,353 times
4 Answers
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
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.

user905686
- 959
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
-
2Of all the answers so far, this was the lightest, easiest install (
brew install qpdf
) on macOS 10.13.6. Also it's very fast. – William Turrell Dec 10 '19 at 10:23
0
- From the Gist:
brew install https://raw.githubusercontent.com/turforlag/homebrew-cervezas/master/pdftk.rb
- 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

Paul Schreiber
- 121
pdfjam
is wrong ;-). – Stephen Kitt Apr 25 '18 at 14:04