#pdf #terminal

I'm often in a situation where I want to extract pages from a PDF file.

As I'm a big fan of the terminal, I always prefer a method that does it via the terminal.

To achieve my goal, a tool called qpdf is used.

If you don't have it installed, you can install it via homebrew if you are on a mac:

brew install qpdf

Once you have it installed, the syntax for extracting pages is like this (docs):

qpdf in.pdf --pages input-file [--password=password] [page-range] [...] -- out.pdf

So, if you want to extract the first 30 pages from a PDF file into another PDF file, you can execute:

qpdf input.pdf --pages . 1-30 -- output.pdf

PS: if you are wondering why the dot is in there, this explains it:

You can use . as a shorthand for the primary input file, if not empty.