How to Merge PDF Files on Linux Command Line (pdfunite)
Merge PDF files on Linux command line with pdfunite from poppler-utils. Covers installation, usage, alternatives (qpdf, Ghostscript), and troubleshooting.

You can merge PDF files on Linux command line in seconds using pdfunite from the poppler-utils package. It is the fastest way to combine PDFs when you are working in a terminal, running batch scripts on a headless server, or automating document pipelines. This guide covers pdfunite in depth, then shows when to reach for alternatives like qpdf (preserves bookmarks and hyperlinks) and Ghostscript (compresses output). If you work with PDFs regularly from the terminal, these are essential Linux commands to have in your toolkit.
What is poppler-utils?
Poppler-utils is a set of command-line utilities built on the poppler PDF library (a fork of xpdf). It ships with most Linux distros and includes six tools:
- pdfinfo: print PDF metadata (title, author, page count, encryption status)
- pdftotext: converts a PDF file to plain text
- pdftohtml: convert PDF to HTML
- pdfimages: extract embedded images from a PDF
- pdfseparate: split a PDF into single-page files
- pdfunite: merge multiple PDF files into one
This article focuses on pdfunite for merging, with coverage of the other tools where they help in a merge workflow (like pdfinfo for verification).
How to install poppler-utils on Linux
Poppler-utils is in the official repos of every major distro. Install it with your package manager.
sudo apt install poppler-utilssudo dnf install poppler-utilssudo pacman -S popplersudo zypper install poppler-toolssudo apk add poppler-utilsbrew install popplerVerify installation
Run pdfunite --version to confirm it is installed. On Ubuntu 24.04 LTS you will see something like:
pdfunite version 24.02.0
Copyright 2005-2024 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011 Glyph & Cog, LLCVersion numbers vary by distro. Ubuntu 24.04 ships 24.02.0, Debian sid has 26.01.0, and the latest upstream release is 26.07.0 (July 2026). Any of these will work fine for merging PDFs.
How to merge PDF files with pdfunite
Basic syntax
The syntax is simple: list the input PDFs first, then the output filename last.
pdfunite file1.pdf file2.pdf file3.pdf output.pdf
This concatenates file1.pdf, file2.pdf, and file3.pdf in that order into output.pdf.
Output file overwritten without warning
pdfunite silently overwrites the output file if it already exists. There is no confirmation prompt. Double-check your output filename before running the command.
Merging with wildcards
You can use shell globbing to merge all PDFs in a directory:
pdfunite *.pdf output.pdf
Wildcard ordering trap
The shell expands * alphabetically, not numerically. If your files are named page_1.pdf, page_2.pdf, …, page_10.pdf, the order will be page_1.pdf, page_10.pdf, page_2.pdf. That is wrong.
Fix: use zero-padded filenames (page_01.pdf, page_02.pdf, …, page_10.pdf) or list files explicitly.
Merging from a file list
If you have a text file listing the PDFs you want to merge (one filename per line), note that pdfunite does not support reading from stdin via a - flag. Use command substitution instead.
Simple approach (works if filenames have no spaces):
pdfunite $(cat files.txt) output.pdf
Safer approach (handles filenames with spaces):
mapfile -t files < files.txt
pdfunite "${files[@]}" output.pdf
The files.txt file should contain one PDF path per line:
report-intro.pdf
report-chapter1.pdf
report-chapter2.pdf
report-appendix.pdf
Verify the merge
After merging, check the page count to confirm all pages are present:
pdfinfo output.pdf | grep "^Pages:"
Compare against the sum of individual page counts:
pdfinfo file1.pdf | grep "^Pages:"
pdfinfo file2.pdf | grep "^Pages:"
pdfinfo output.pdf | grep "^Pages:" # should equal the sum
Also check the file is not empty:
ls -lh output.pdf
Limitations of pdfunite (what you should know)
pdfunite is fast and simple, but it concatenates PDFs at the page content level. This means:
- Hyperlinks are lost. Internal TOC links and cross-references break after merging.
- Bookmarks/outlines are stripped. PDF outlines (the sidebar navigation in viewers like Evince or Acrobat) disappear.
- No encryption support. You cannot merge password-protected PDFs directly.
- No page manipulation. You cannot rotate, reorder, or extract specific pages.
- No compression. The output file can be larger than expected.
pdfunite strips hyperlinks and bookmarks
If your PDFs have a table of contents with clickable links or PDF outlines/bookmarks, do not use pdfunite. Use qpdf instead. It preserves both.
For simple merges (combining invoices, scanned pages, or reports without internal links), pdfunite is the right tool. If you need bookmarks or hyperlinks to survive, switch to qpdf.
Alternative tools for merging PDFs on Linux
When pdfunite is not enough, these three tools cover the gaps.
qpdf: preserve hyperlinks and bookmarks
qpdf is the best alternative when you need to preserve PDF structure. It handles encryption, page ranges, and keeps bookmarks and hyperlinks intact.
Install:
# Debian / Ubuntu
sudo apt install qpdf
# RHEL / Fedora
sudo dnf install qpdf
# Arch Linux
sudo pacman -S qpdfMerge PDFs:
qpdf --empty --pages file1.pdf file2.pdf file3.pdf -- output.pdfMerge specific page ranges:
# Pages 1-5 from file1, all pages from file2
qpdf --empty --pages file1.pdf 1-5 file2.pdf 1-z -- output.pdfDecrypt then merge:
qpdf --decrypt --password=SECRET encrypted.pdf decrypted.pdf
pdfunite decrypted.pdf other.pdf merged.pdfGhostscript: merge and compress
Ghostscript is heavier (~30 MB install) but does something no other lightweight tool does: compress PDFs during or after merging. Good for reducing file size before uploading or emailing.
Install:
# Debian / Ubuntu
sudo apt install ghostscript
# RHEL / Fedora
sudo dnf install ghostscript
# Arch Linux
sudo pacman -S ghostscriptMerge and compress in one step:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
-dPDFSETTINGS=/ebook \
-sOutputFile=merged.pdf file1.pdf file2.pdfCompress an existing PDF:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH \
-sOutputFile=compressed.pdf merged.pdfPDFSETTINGS quality levels:
| Setting | DPI | Use case |
|---|---|---|
/screen |
72 | Smallest file, screen-only reading |
/ebook |
150 | Good balance of size and quality |
/printer |
300 | High quality for printing |
/prepress |
300 | Color-preserving, largest file |
stapler: lightweight pdftk replacement
pdftk was removed from Fedora repos in 2019 and is hard to install on modern Ubuntu due to its gcj dependency. stapler is a Python-based replacement that does page-level operations.
Install:
# Via pip (any distro)
pip install stapler
# Fedora
sudo dnf install pdf-staplerMerge PDFs:
stapler sel file1.pdf file2.pdf output.pdfstapler also supports page selection, splitting, and other pdftk-like operations. If you need a pdftk-compatible interface without the install headaches, stapler is the tool to use.
Tool comparison table
| Feature | pdfunite | qpdf | Ghostscript | stapler |
|---|---|---|---|---|
| Simple merge | ✅ Best | ✅ Good | ✅ Works | ✅ Good |
| Preserve hyperlinks | ❌ | ✅ | ❌ | ✅ |
| Preserve bookmarks | ❌ | ✅ | ❌ | ✅ |
| Handle encrypted PDFs | ❌ | ✅ Best | Limited | Limited |
| Compress output | ❌ | Limited | ✅ Best | ❌ |
| Page-level ops | ❌ | ✅ | Limited | ✅ Best |
| Speed | Very fast | Fast | Slower | Fast |
| Package size | under 1 MB | ~3 MB | ~30 MB | ~14 MB |
| In modern distro repos | ✅ | ✅ | ✅ | ❌ (pdftk removed) |
Which tool should I use?
Start with pdfunite for simple merges. It is the fastest and lightest. Switch to qpdf when bookmarks, hyperlinks, or encrypted PDFs matter. Use Ghostscript when you need to compress the output. Use stapler when you need pdftk-style page manipulation.
Real-world workflows and automation
Batch merge script with validation
This script validates all input files exist, merges them, and reports the page count:
#!/bin/bash
set -euo pipefail
OUTPUT="${1:-merged.pdf}"
shift
# Validate all inputs exist
for f in "$@"; do
[[ -f "$f" ]] || { echo "ERROR: File not found: $f" >&2; exit 1; }
done
pdfunite "$@" "$OUTPUT"
echo "Created: $OUTPUT ($(pdfinfo "$OUTPUT" | grep "^Pages:" | awk '{print $2}') pages)"
Usage:
chmod +x merge-pdfs.sh
./merge-pdfs.sh combined-report.pdf chapter1.pdf chapter2.pdf chapter3.pdf
For more advanced automation workflows, you can integrate PDF processing into tools like n8n for document processing pipelines.
Handling encrypted PDFs
pdfunite cannot process password-protected PDFs. Decrypt them first with qpdf:
# Decrypt
qpdf --decrypt --password=THEPASS protected.pdf unprotected.pdf
# Then merge as usual
pdfunite unprotected.pdf other.pdf merged.pdf
# Clean up the decrypted file
rm unprotected.pdf
Verifying the merge
Always verify after merging, especially in scripts:
# Check total page count matches sum of inputs
EXPECTED=$(pdfinfo file1.pdf | grep "^Pages:" | awk '{sum += $2} END {print sum}')
EXPECTED=$((EXPECTED + $(pdfinfo file2.pdf | grep "^Pages:" | awk '{print $2}')))
ACTUAL=$(pdfinfo output.pdf | grep "^Pages:" | awk '{print $2}')
if [[ "$EXPECTED" -eq "$ACTUAL" ]]; then
echo "OK: $ACTUAL pages"
else
echo "MISMATCH: expected $EXPECTED, got $ACTUAL" >&2
exit 1
fi
Keeping poppler-utils updated (security)
Keep poppler-utils updated
Poppler processes arbitrary PDF files, and it has had multiple CVEs (CVE-2026-10118, CVE-2025-52885, CVE-2025-43718, and others). If you are merging PDFs from untrusted sources, keep the package updated and consider running CLI tools in isolated environments.
# Debian / Ubuntu
sudo apt update && sudo apt upgrade poppler-utils
# RHEL / Fedora
sudo dnf upgrade poppler-utilsTroubleshooting common errors
Permission denied
You do not have read or write permission on the PDF files.
# Check permissions
ls -l file.pdf
# Fix: give owner read+write
chmod u+rw file.pdfIf the files are owned by another user, you may need sudo or to change ownership with chown.
File not found
The file does not exist or the filename is wrong.
# Check your working directory
pwd
# List PDFs in the current directory
ls *.pdf
# Use tab completion to avoid typos
pdfunite file1<TAB>If you are running the command in a script, use absolute paths or verify the working directory first.
Invalid or damaged PDF file
The PDF is corrupted. Unlike what some guides claim, pdfinfo does not have a -repair flag. Use one of these tools to attempt repair:
With qpdf (rebuilds the PDF structure):
qpdf --check damaged.pdf
qpdf --qdf damaged.pdf repaired.pdfWith Ghostscript (rewrites the entire PDF):
gs -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress damaged.pdfWith pdftk (if installed):
pdftk damaged.pdf output repaired.pdfIf none of these work, the file is likely beyond repair. Compare file sizes with comparing folders on the command line if you have a backup to check against.
Command not found: pdfunite
poppler-utils is not installed. Verify:
which pdfunite
# No output = not installedGo back to the installation section and install it for your distro.
Memory issues with large PDFs
pdfunite loads full PDFs into memory. If you are merging files that are hundreds of MB each, you may run into memory pressure. Check your system resources:
# Check available memory
free -h
# Monitor swap usage
swapon --showFor very large files, consider Ghostscript which uses a streaming approach:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-sOutputFile=merged.pdf large1.pdf large2.pdfIf you need to monitor Linux system resources during batch operations, set up alerts so you catch OOM conditions early.
Conclusion
For merging PDF files on the Linux command line, the tool you pick depends on what you need:
- pdfunite: default choice for simple merges. Fast, tiny, already installed on most systems.
- qpdf: use when bookmarks, hyperlinks, or encrypted PDFs are involved.
- Ghostscript: use when you need to compress the output or merge very large files.
- stapler: use when you need pdftk-style page manipulation.
Companion poppler tools are useful in a merge workflow: pdfinfo to check page counts and encryption status before merging, pdfseparate to split a PDF (the reverse operation), and pdftotext to extract text for verification.
If you run a VPS or headless server and process PDFs regularly, keep poppler-utils updated and consider securing your Linux server if it handles files from external sources.
Explore more Linux commandsFAQ
Can pdfunite merge password-protected PDFs?
No. pdfunite cannot process encrypted PDFs. Decrypt them first with qpdf:
qpdf --decrypt --password=THEPASS protected.pdf unprotected.pdf
pdfunite unprotected.pdf other.pdf merged.pdfDoes pdfunite preserve bookmarks and hyperlinks?
No. pdfunite concatenates page content at a low level, which strips bookmarks (outlines) and breaks internal hyperlinks. If you need these preserved, use qpdf instead:
qpdf --empty --pages file1.pdf file2.pdf -- output.pdfWhat is the difference between pdfunite and qpdf?
pdfunite is simpler and lighter (under 1 MB, fastest). It is great for basic merges where you do not care about bookmarks or hyperlinks. qpdf is heavier (~3 MB) but preserves PDF structure, handles encrypted files, supports page ranges, and can decrypt PDFs. For most people, start with pdfunite and switch to qpdf when you hit a limitation.
How do I merge PDFs in a specific order?
List the files explicitly in the order you want:
pdfunite intro.pdf chapter1.pdf chapter2.pdf appendix.pdf output.pdfIf using wildcards, shell glob expansion is alphabetical: page_1.pdf comes before page_10.pdf, not page_2.pdf. Use zero-padded filenames (page_01.pdf, page_02.pdf, …, page_10.pdf) to get correct numerical ordering.


