Sometimes there is a need to amalgamate many PDFs into a single PDF. Ghostscript is fully capable of achieving this and is usually available by default.
To concatenate any number of PDFs, cd to the appropriate directory containing the PDF files and issue the following command:
$ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=finished.pdf -dBATCH *.pdf
Note that they are added to the finalised PDF in the order given – so “*.pdf” may not result in the order you would like, in which case you will need to manually specify each file in the desired order.
A quick breakdown to the options:
-dBATCH : Exit once Ghostscript processes the PDF files, otherwise Ghostscript will keep running
-dNOPAUSE : tells Ghostscript to process each page without pausing for user interaction
-sDEVICE=pdfwrite : tells Ghostscript to use its built-in PDF writer to process the files
-sOutputFile=finished.pdf : tells Ghostscript to save the output to the named file, in this case “finished.pdf”
Additional options you may want:
-sPAPERSIZE=letter : sets the paper size to American sized “letter”
-q : “quiet” mode, stops Ghostscript displaying messages while it works