Ubuntu – Rearrange PDF pages using the command-line

command linepdf

I want to rearrange the pages in a PDF file. But because I have to rearrange many pages, and the new arrangement has a specific pattern, I would like to do so with a script. Is there a simple program which allows to rearrange the pages in a PDF?

Alternatively I could also extract all pages and merge them together in the order I want. What progams are available to do this?

Best Answer

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.