Concatenate multiple PDF files into one PDF file

For this purpose we need ghostscript, but basically this software comes pre-installed in most linux distribution.

So to concatenate multiple PDFs (file1.pdf, file2.pdf, file3.pdf), into one file (output.pdf), simply run this:

$ gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1pdf file2.pdf file3.pdf

Yes, it’s a long command, I know. To change the output paper size we can replace “a4” with “legal” for US Legal or “letter” for US Letter.

Convert Multiple Images Into PDF in Ubuntu Linux

First of all make sure you have imagemagick installed, otherwise checking won’t hurt:
$ sudo apt-get install imagemagick

Then in this case, I would like to join multiple image files of scanned documents with sortable file names (e.g. file01.jpg, file02.jpg, etc.). Finally to join those files together in A4 PDF format we do this in terminal:
$ convert -page A4+0+0 file* OutputFile.pdf

Combining Multiple PDF Files Into One PDF File in Linux

This post is inspired (and 68% taken) from here. 😀

There are times when you need to combine multiple PDF files into one single PDF file. In Windows or Mac, it’s easy (as long as you are willing to spend some amount of money to buy the software), you can use Adobe Acrobat Professional. Sadly Adobe didn’t come up with Acrobat Professional for Linux platform, but luckily we have several options to do such job in a Linux box. Here’s one.

GhostScript is an interpreter for PostScript language and PDF files, and as far as I know, GhostScript is widely available by default on various Linux distro. In this post I will show you a simple trick to use GhostScript to combine any numbers of PDF files into one single PDF file. Although combining files with GhostScript has its own drawbacks, but still, for most purposes GhostScript does the job well.

Here’s the voodoo mantra, spell them on Linux terminal:
$ gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf ...

And below is the explanation of each mantra:

  • gs
    The GhostScript program.
  • -dBATCH
    tells the program to exit after finishing the job.
    tells the program to keep going without having conversation with the user.
  • -sDEVICE=pdfwrite
    tells the program to use its internal PDF writer to process the files.
  • -sOutputFile=finished.pdf
    tells the program where to put those scattered PDF files into one file whom name you specified.
  • file1.pdf file2.pdf …
    tells the program which PDFs you want to combine.

Tada, now you have combined PDF file, ready to brought anywhere without worry leaving one part behind.