Working with contracts and other legal documents gets easier once you know how to digitally sign and edit PDFs. It can simply become a minor inconvenience once you know how to merge PDF files in the Linux terminal or any free graphical application. Then, you’re not stuck adding multiple PDFs to your website, annoying your readers and business partners as a result.
A lot of desktop and online options show in search engine results for “how to merge two PDF files.” Some of the most popular, reputable applications:
Problem is that none of those above are free, light-weight, private, and fitting answers for how to merge PDF files in the Linux server command line interface (CLI). Below we’ll cover:
- How to Merge PDF Files in the Linux Terminal
If you don’t need cPanel, don't pay for it. Only pay for what you need with our Cloud VPS solutions.
CentOS, Debian, or Ubuntu No bloatware SSH Key management made easy
How to Merge PDF Files in the Linux Terminal
- First, open a Linux terminal. If working on a Linux server, log into SSH. cPanel server administrators can use cPanel Terminal or WebHost Manager (WHM) Terminal. Root access won’t matter in most cases.
- These commands are easier when you don’t have to repeatedly type full file paths from your home directory. If all or most PDF files are in the same directory, navigate to that directory with the
- Before installing a PDF merger below, check if you already have a PDF editor installed. Type
Convert ImageMagick Tool
ImageMagick is installed on all InMotion cPanel servers. Primarily for image optimization, ImageMagick includes a conversion tool that can merge PDFs:
convert. Type the program command, original PDFs in the order to be merged, then the filename for the final, merged PDF file.
convert file1.pdf file2.pdf mergedfile.pdf
You may receive the following error on a cPanel server-
convert: unable to access configure file `delegates.xml' @ warning/configure.c/GetConfigureOptions/677. If so, run
convert by itself. If that returns info about using the tool, your cPanel server administrator may have set your user to a jailed shell for better security, removing your access to the ImageMagick delegates.xml file. We recommend trying GhostScript (below) before asking for normal shell access.
To merge specific pages from PDFs, specify the pages starting from 0. For example, to merge pages 1-2 of a PDF with a second file:
convert file1.pdf[0-1] file2.pdf mergedfile.pdf
Install ImageMagick on CentOS:
sudo yum install ImageMagick
Install ImageMagick on Debian / Ubuntu:
sudo apt install imagemagick
Learn more about how to convert and resize files with ImageMagick.
Ghostscript is installed on InMotion cPanel servers, CentOS cloud servers, and many desktop Linux distros. It is a versatile CLI app for manipulating PDF, XPS, and PostScript files. We’ll use
-dNOPAUSE to disable continuation prompts at the end of each page. The
-sDEVICE attribute designates the output device or function. You can see the full list with
gs -h command.
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=mergedfile.pdf -dBATCH file1.pdf file2.pdf
Install Ghostscript on CentOS:
sudo yum install ghostscript
Install Ghostscript on Debian / Ubuntu:
sudo apt-get install ghostscript
pdfunite, by Poppler, is natively installed on Ubuntu-based Mint Cinnamon and Arch-based Manjaro. The command format is the same as the convert tool.
pdfunite file1.pdf file2.pdf mergedfile.pdf
Install PDFunite on CentOS:
sudo dnf install poppler-utils
Install PDF on Debian / Ubuntu:
sudo apt install poppler-utils
PDFtk (PDF Toolkit)
The PDF Toolkit has graphical and paid options. The format is a little different for PDFtk. You must add “cat output” between the original PDFs and the new PDF file.
pdftk file1.pdf file2.pdf cat output mergedfile.pdf
See official documentation to install PDFtk on CentOS 6.
To install PDFtk on CentOS 7, read more about libgcj dependency issues and possible solutions from a docsplit GitHub thread.
Install PDFtk on Debian / Ubuntu:
sudo apt install pdftk-java
Learn more from our Cloud Server Hosting Product Guide.