HowTo: Merge PDF Files – Linux Command Line

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.

Cool Tip: Merge PDF files in Linux using the ghostscript command! Read more →

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

$ sudo apt-get install imagemagick

Convert Multiple PDF Files Into One

Merge two PDF files FILE1.pdf and FILE2.pdf into the new OUTPUT.pdf file:

$ convert FILE1.pdf FILE2.pdf OUTPUT.pdf

Merge Specific Pages Into One PDF File

Note: The count of the pages starts from zero.

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

For this we will pass our filenames with the required page numbers in the square brackets to the convert command.

Merge the second page from the first file FILE1.pdf with the first and the sixth pages from the second file FILE2.pdf and save the result to the new OUTPUT.pdf file:

$ convert FILE1.pdf[1] FILE2.pdf[0,5] OUTPUT.pdf

Join Ranges of Pages Into Single PDF File

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

Cool Tip: Plan to send this PDF somewhere or just keep? How about to protect it with a password? This is really easy for ones who merge PDF files from the command line! Read more →

Join the first ten pages from first file FILE1.pdf with the first five pages from the second file FILE2.pdf and save the result to the new OUTPUT.pdf file:

$ convert FILE1.pdf[0-9] FILE2.pdf[0-4] OUTPUT.pdf
Was it useful? Share this post with the world!

7 Replies to “HowTo: Merge PDF Files – Linux Command Line”

  1. $ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
    1. Ghostscript гораздо качественней преобразовывает файлы — без сжатия и артефактов в изображениях

    2. This worked great! Ghostscript keeps the quality of the pdf files AND is way faster! Thanks!

    3. Thanks MAXIM. That works great

  2. @MAXIM your command is nice since it keeps the embedded fonts. the `convert` command had slight problem for embed fonts (make the output is not clear as original)

  3. imagemagik or how they spell it is useful tool for many things. Unfortunately, he butchers the pdf so it does not have correct resolution of original files. It becomes difficult to read a merged copy.

  4. You need a special -density flag with dpi value corresponding to the original file quality, because the default value is about 90.
    convert FILE1.pdf FILE2.pdf -density 200 OUTPUT.pdf
    or
    convert -density 200 FILE1.pdf FILE2.pdf OUTPUT.pdf

Leave a Reply