Concatenating PDF Files on Linux

I’ve had this socked away for a while, but was just reminded of it.  This is a method of concatenating PDF files.  This takes multiple PDF files as inputs and outputs a single PDF file made up of those.  This is particularly useful when a document needs to include sub-documents, such as a report that includes preexisting data sheets, or a proposal needs to include financial statements, resumes, or other supporting documents.

If you’re running any of the mainstream GNU/Linux distributions (and chose to install printing software, if that was given as an option), you probably already have ghostscript installed.  Ghostscript is commonly used in the internals of the printing system on Linux, and can also manipulate PDF files.  A single command invoking Ghostscript can do what we need:

gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf file3.pdf [...] lastfile.pdf

Note that there are other options for paper size, particularly if you’re outside the US (where something like A might be more appropriate).  Here is a list of the paper sizes Ghostscript knows about.

Leave a Reply