Rearrange PDF pages using the command-line

Solution 1:

pdftk is the one you're searching for. E.g. if you want to reverse the page order of i.pdf, do

pdftk i.pdf cat end-1 output o.pdf

Other examples showing pdftk's potential:

pdftk i.pdf cat 4-1 6 8-end output o.pdf # use ranges
pdftk i.pdf cat 1-6even output o.pdf     # print only even pages in the range
pdftk i.pdf cat 1-10 ~5-7 output o.pdf   # exclude pages in the range
pdftk i.pdf burst                        # extract to single-page pdf files

Read man pdftk for more information.

To install pdftk on 18.04 see: How can I install pdftk in Ubuntu 18.04 Bionic?


If you after all search for a GUI solution have a look at pdftk's GUI pdfchain or pdfmod.

Solution 2:

You can also try pdfjam pdfnup (based on LaTeX pdf-pages)

Example:

pdfjam i.pdf '{},2,1-5'         -o o.pdf
pdfjam f1.pdf f2.pdf f3.pdf 1-3 -o o.pdf   ## first 3 pages from f1,f2,f3 
  • {} inserts an empty page
  • many options available (ex: scale, offset, trim, frame, nup) -- see pdfjam man

Solution 3:

You can use qpdf which comes with ubuntu. This following command for example puts the pages in reverse order.

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

You can find more information and other examples here on pages 10 and 11.