How to Merge PDF Files in the Linux Terminal

How to Merge PDF Files in the Linux Terminal - 4 Options

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.

How to merge PDF files in Libre Office Draw

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:

If you don’t need cPanel, don't pay for it. Only pay for what you need with our scalable Cloud VPS Hosting.

check markCentOS, Debian, or Ubuntu check markNo Bloatware check markSSH and Root Access

How to Merge PDF Files in the Linux Terminal

  1. 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.
  2. 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 cd command
  3. Before installing a PDF merger below, check if you already have a PDF editor installed. Type pdf and press Tab twice to see what programs are listed. If anything shows up, check the manual to learn what it does:
    man pdfapplication

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

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

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.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!