How to concatenate PDFs in Linux

Sometimes you want to append one PDF file onto the end of another. Here’s how to do it in Linux using the Ghostscript tool.

Howto concatenate PDFs in Linux

How To: Concatenate PDF files in Linux

When I am working in Inkscape I often want to put together multiple-page graphics. Sadly Inkscape doesn’t yet support multiple page documents, although they are planning this feature and so it shouldn’t be too long before it does. So the way I work around this is to create multiple documents, one for each page, then use “Print to file” to save each one as a PDF. Now I have, say, 3 PDFs. All I need do now is concatenate them to create one single PDF that I can send to the customer.

Here’s one way to do it using GhostScript from the command line:

gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=logo-concepts.pdf logo-concepts-1.pdf logo-concepts-2.pdf logo-concepts-3.pdf

In this example logo-concepts.pdf is the finished PDF with all pages appended, and logo-concepts-1.pdf, logo-concepts-2.pdf and logo-concepts-3.pdf are the individual pages. You can tweak “-sPAPERSIZE=” to suit your needs.

Another Method

As “anon” points out in the comments it is also possible to use the command “pdfjoin”, if you have it installed. The program is part of the “pdfjam” package which, at a hefty 389mb of dependencies, may not be ideal for you. Installing the package is easy though:

sudo apt-get install pdfjam

After the package and its dependencies have been installed you can simply use

pdfjoin logo-concepts-1.pdf logo-concepts-2.pdf logo-concepts-3.pdf

pdfjoin will choose a filename for the joined file for you. In this example it would create a file named logo-concepts-3-joined.pdf.


About Matt Lowe

Matt Lowe is a WordPress web designer / developer based in Newbury, Berkshire. After 8 years of doing the nine-to-five for other companies and watching them make the same mistakes over and over he set out in business on his own. He writes in the third person. Read more »

Posted on by Matt Lowe This entry was posted in Content, Squelch Web Design Blog and tagged , , .


5 meditations upon How to concatenate PDFs in Linux

  1. On anon was pontificating thus:

    pdfjoin file1.pdf file2.pdf file3.pdf

    • On Matt Lowe was pontificating thus:

      Yes, granted that’s an easier way of doing it if you have the command installed. You need to install the “pdfjam” package first though, on Ubuntu:

      sudo apt-get install pdfjam

      I’ll update the article to include this method, thanks for your comment. :)

  2. On Adrian was pontificating thus:

    I just discovered that I already had pdfjam installed on my computer (Ubuntu 12.10) as a part of texlive-extra-utils – this should explain why it has this slew of dependencies. Interestingly, it actually calls pdflatex and is not just a sophisticated wrapper for Ghostscript.

    Another alternative would be pdftk (PDF Toolkit), which in turn requires GCJ and therefore has quite some overhead, too. For simple tasks like concatenation, bare-bones Ghostscript (which should already be a part of your system) is probably the easiest solution, even if the command-line syntax is slightly more complicated than for a dedicated concatenation tool.

  3. On Derek was pontificating thus:

    Try pdftk (23Mb).

Leave a Comment

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>