HowTo: Merge PDF Files in Linux

Sometimes it is required to merge several PDF files into a one PDF file.

In Linux we can easily join multiple PDF files using the command line utility called convert that is a part of ImageMagick software suite.

From this article you will learn how to merge entire PDF files into one PDF file or how to join specific PDF pages only into a single PDF file.

First of all it is required to install the ImageMagick suite that provides the convert utility:

$ sudo yum install imagemagick
- or -
$ sudo apt-get install imagemagick

Read more: Creating ASCII Text Banners from the Linux Command Line

Converting Multiple PDF Files Into One

Merge two PDF files (file1.pdf and file2.pdf) into the new file (output.pdf):

$ convert file1.pdf file2.pdf output.pdf

Merging Specific Pages Into One PDF File

It is also possible to convert specific PDF pages into a single PDF file.

Merge the 2nd page from the first file (file1.pdf) with the 1st and the 6th pages from the second file (file2.pdf) and save the result to the new file (output.pdf):

$ convert file1.pdf[1] file2.pdf[0,5] output.pdf

Note that the count of the pages starts from zero.

Join Ranges of Pages Into Single PDF File

And of course it is possible to join the some ranges of pages.

Read more: What is my Public IP address?

Join the first 10 pages from first file (file1.pdf) with the first 5 pages from the second file (file2.pdf) and save the result to the new file (output.pdf):

$ convert file1.pdf[0-9] file2.pdf[0-4] output.pdf