# How to split/join pdf files

Ghostscript is a very useful tool in this situation.

• Install `ghostscript` (the `gs` command line).
``sudo apt install -yq ghostscript``
• To extract pages from the 3rd page to the 5th page in `in.pdf` , write output to `out.pdf`
``gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=3 -dLastPage=5 -sOutputFile=out.pdf in.pdf``

By default `-dFirstPage` is 1,  `-dLastPage` is the last page number.

• To combine 2 pdf files `in1.pdf` `in2.pdf`, write output to `out.pdf`.
``gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=out.pdf in1.pdf in2.pdf``