How to Merge PDF Files in Bash?

Merging PDF files in Linux is a common task for organizing documents, reducing clutter, or preparing files for sharing. Linux provides several powerful command-line utilities specifically designed for this purpose. Each tool offers different features and syntax, making them suitable for various use cases.

Available PDF Merging Tools

Linux offers multiple utilities for merging PDF files

  • pdfunite Part of Poppler Utils, simple and fast

  • pdftk PDF Toolkit with advanced features

  • qpdf Powerful PDF transformation utility

  • gs (Ghostscript) PostScript and PDF processor

  • convert (ImageMagick) Image manipulation tool with PDF support

We'll focus on the three most commonly used tools for merging functionality.

Using pdfunite

pdfunite is part of the Poppler Utils package and provides the simplest syntax for merging PDF files. First, install the required package

sudo dnf install poppler-utils    # RHEL/CentOS/Fedora
sudo apt install poppler-utils    # Ubuntu/Debian

Basic Syntax

pdfunite input1.pdf input2.pdf [input3.pdf ...] output.pdf

Example

Let's merge two PDF files Linux.pdf and ShellIntro.pdf

[root@localhost ~]# ls -lh *.pdf
-rw-r--r-- 1 root root 4.3M Oct  8 06:29 Linux.pdf
-rw-r--r-- 1 root root 125K Oct  8 06:29 ShellIntro.pdf
pdfunite Linux.pdf ShellIntro.pdf Merged.pdf
[root@localhost ~]# ls -lh *.pdf
-rw-r--r-- 1 root root 4.3M Oct  8 06:29 Linux.pdf
-rw-r--r-- 1 root root 4.6M Oct  8 07:29 Merged.pdf
-rw-r--r-- 1 root root 125K Oct  8 06:29 ShellIntro.pdf

Using pdftk

pdftk (PDF Toolkit) is a versatile tool that offers more advanced PDF manipulation features beyond simple merging.

Installation

sudo dnf install pdftk           # RHEL/CentOS/Fedora
sudo apt install pdftk          # Ubuntu/Debian

Basic Syntax

pdftk input1.pdf input2.pdf cat output merged.pdf

Example

pdftk Linux.pdf ShellIntro.pdf cat output mergedfile.pdf
[root@localhost ~]# ls -lh *merged*.pdf
-rw-r--r-- 1 root root 4.5M Oct  8 07:52 mergedfile.pdf

The cat keyword tells pdftk to concatenate all pages from the input files in the specified order.

Using qpdf

qpdf is designed for PDF transformation and reorganization. It's particularly useful when you need to merge specific pages or ranges from multiple PDF files.

Installation

sudo dnf install qpdf            # RHEL/CentOS/Fedora
sudo apt install qpdf           # Ubuntu/Debian

Basic Syntax for Merging

qpdf --empty --pages input1.pdf input2.pdf -- output.pdf

Example

qpdf --empty --pages Linux.pdf ShellIntro.pdf -- combined.pdf
[root@localhost ~]# ls -lh combined.pdf
-rw-r--r-- 1 root root 4.5M Oct  8 08:11 combined.pdf

Command Options Explained

  • --empty Creates an empty document as the starting point

  • --pages Specifies the input PDF files to merge

  • -- Separates page specifications from the output filename

Comparison of Tools

Tool Ease of Use Speed Advanced Features Best For
pdfunite Very Easy Fast Basic Simple merging tasks
pdftk Moderate Good Extensive Complex PDF operations
qpdf Moderate Good Very Extensive PDF transformation & repair

Common Use Cases

  • Document consolidation Combining related reports or chapters

  • Archive creation Merging invoices or receipts by month

  • Batch processing Automating PDF merging in shell scripts

  • File size management Reducing the number of separate PDF files

Conclusion

Linux provides excellent command-line tools for merging PDF files, each with distinct advantages. Use pdfunite for simple, fast merging tasks, pdftk for more complex operations, and qpdf for advanced PDF transformation needs. All three tools preserve document quality and metadata during the merging process.

Updated on: 2026-03-17T09:01:38+05:30

754 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements