Home PDFHow to Merge PDF Files in Linux with pdfunite Command (2026 Guide)

How to Merge PDF Files in Linux with pdfunite Command (2026 Guide)

By sk
1.3K views 8 mins read

Need to combine multiple PDF files into one document on Linux? The pdfunite command provides the fastest and simplest way to merge PDFs directly from your terminal. This comprehensive guide covers everything from basic installation to advanced scripting techniques for batch PDF operations.

What is pdfunite?

pdfunite is a lightweight command-line tool that merges multiple PDF files into a single document. Part of the Poppler utilities suite (based on the Poppler PDF rendering library), it excels at one task: fast, straightforward PDF concatenation.

Key advantages:

  • Lightning-fast merging
  • Simple, intuitive syntax
  • Minimal disk footprint (under 200KB)
  • Pre-installed on many Linux distributions
  • Perfect for automation and scripting

Important limitation: pdfunite breaks internal hyperlinks and bookmarks in the merged output. For preserving these elements, use pdftk instead.

Installation

Arch Linux, Manjaro, EndeavourOS:

sudo pacman -S poppler

Debian, Ubuntu, Linux Mint, Pop!_OS:

sudo apt update
sudo apt install poppler-utils

Fedora, RHEL, CentOS, AlmaLinux, Rocky Linux:

sudo dnf install poppler-utils

openSUSE:

sudo zypper install poppler-tools

Once installed, you verify using command:

pdfunite --version

Sample Output:

pdfunite version 22.12.0
Copyright 2005-2022 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011, 2022 Glyph & Cog, LLC
Usage: pdfunite [options] <PDF-sourcefile-1>..<PDF-sourcefile-n> <PDF-destfile>
  -v             : print copyright and version info
  -h             : print usage information
  -help          : print usage information
  --help         : print usage information
  -?             : print usage information

If the command returns "command not found", the package isn't installed correctly. Check your package manager syntax for your specific distribution.

Basic Usage: Merge PDF Files

The syntax is straightforward:

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

Important: The last argument is always the output file. All preceding files are inputs merged in the specified order.

Real-World Examples

Combine monthly reports:

pdfunite january_sales.pdf february_sales.pdf march_sales.pdf q1_report.pdf

Merge scanned documents:

pdfunite contract_page1.pdf contract_page2.pdf contract_page3.pdf full_contract.pdf

Combine invoice files:

pdfunite invoice_001.pdf invoice_002.pdf invoice_003.pdf invoices_batch.pdf

Warning: If output.pdf already exists, pdfunite overwrites it without confirmation. Always double-check your output filename.

Working with Multiple Files

Merge All PDFs in Current Directory

pdfunite *.pdf combined.pdf

Important: Shell wildcards expand alphabetically. For numbered files, use zero-padding (page_01.pdf, page_02.pdf) to ensure correct ordering, not page_1.pdf, page_10.pdf, page_2.pdf.

Merge PDFs from Different Directories

pdfunite /home/user/docs/report1.pdf /home/user/downloads/report2.pdf ~/merged_report.pdf

Merge Files Listed in a Text File

Create files.txt:

chapter1.pdf
chapter2.pdf
chapter3.pdf
appendix.pdf

Then merge:

pdfunite $(cat files.txt) complete_book.pdf

Warning: This method breaks if filenames contain spaces or special characters.

For example, this will fail or behave incorrectly:

chapter 1.pdf
chapter 2.pdf

because command substitution splits on whitespace.

This is not a pdfunite limitation, it is how shell word splitting works.

Advanced Scripting and Automation

Batch Merge with Error Handling

#!/bin/bash
# merge_pdfs.sh - Professional PDF merging script

INPUT_FILES=("report_part1.pdf" "report_part2.pdf" "appendix.pdf")
OUTPUT="final_report.pdf"

# Validate all input files exist
for file in "${INPUT_FILES[@]}"; do
  if [[ ! -f "$file" ]]; then
    echo "Error: File '$file' not found"
    exit 1
  fi
done

# Perform merge
if pdfunite "${INPUT_FILES[@]}" "$OUTPUT"; then
  echo "Success: Created $OUTPUT ($(du -h "$OUTPUT" | cut -f1))"
  ls -lh "$OUTPUT"
else
  echo "Error: Merge failed"
  exit 1
fi

Merge PDFs Modified Recently

#!/bin/bash
# Merge all PDFs modified in the last 7 days

find . -name "*.pdf" -mtime -7 -print0 | \
  sort -z | \
  xargs -0 sh -c 'pdfunite "$@" recent_merged.pdf' sh

Merge by Date Range

#!/bin/bash
# Merge PDFs modified between specific dates

mapfile -d '' FILES < <(
  find . -name "*.pdf" -newermt "2026-01-01" ! -newermt "2026-01-31" -print0 | sort -z
)

pdfunite "${FILES[@]}" monthly_archive_jan2026.pdf

Loop Through Subdirectories

#!/bin/bash
# Merge PDFs in each subdirectory separately

for dir in */; do
  if ls "$dir"*.pdf 1> /dev/null 2>&1; then
    output="${dir%/}_merged.pdf"
    pdfunite "$dir"*.pdf "$output"
    echo "Created: $output"
  fi
done

Limitations and Workarounds

What pdfunite Cannot Do

OperationpdfuniteAlternative Tool
Preserve hyperlinks❌ No✅ pdftk
Preserve bookmarks❌ No✅ pdftk
Reorder pages❌ No✅ pdftk, qpdf
Remove pages❌ No✅ pdftk, qpdf
Compress output❌ No✅ ghostscript
Add metadata❌ No✅ pdftk
Merge encrypted PDFs❌ No*✅ qpdf (with decrypt)

*Requires decryption first

Handling Encrypted PDFs

Error message:

Error: Couldn't open file 'encrypted.pdf': Incorrect password

Solution using qpdf:

For password-protected PDFs:

qpdf --decrypt --password=YOUR_PASSWORD encrypted.pdf decrypted.pdf
pdfunite decrypted.pdf other.pdf merged.pdf

For PDFs with only copy/print restrictions (no user password):

qpdf --decrypt restricted.pdf unrestricted.pdf
pdfunite unrestricted.pdf other.pdf merged.pdf

Large File Performance

pdfunite may use significant memory when merging very large PDFs (hundreds of MB or more), since it rewrites the document structure in one pass.

Option 1: Use ghostscript (streaming)

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
   -sOutputFile=merged.pdf file1.pdf file2.pdf

Option 2: Split, merge, recombine

pdftk large.pdf burst output page_%04d.pdf
# Process in smaller batches
pdfunite page_0001.pdf page_0002.pdf ... batch1.pdf

Troubleshooting Common Errors

Command Not Found

Problem: bash: pdfunite: command not found

Solutions:

# Verify installation
which pdfunite

# Check package installation
dpkg -l | grep poppler-utils  # Debian/Ubuntu
rpm -qa | grep poppler-utils  # Fedora/RHEL

# Reinstall if necessary
sudo apt install --reinstall poppler-utils

Syntax Error: Missing Output File

Problem: Syntax Error: May not use this file more than once

Cause: Forgot to specify output filename

Wrong:

pdfunite file1.pdf file2.pdf  # Missing output!

Correct:

pdfunite file1.pdf file2.pdf output.pdf

File Not Found

Problem: Error: Couldn't open file 'report.pdf'

Solutions:

# Verify file exists
ls -la report.pdf

# Check current directory
pwd
ls *.pdf

# Use absolute paths
pdfunite /full/path/to/file1.pdf /full/path/to/file2.pdf output.pdf

# Check file permissions
chmod 644 restricted_file.pdf

Corrupted PDF Error

Problem: Error: PDF file is damaged

Solutions:

# Rewrite the PDF structure (may fix minor issues):
qpdf --check damaged.pdf
qpdf --qdf damaged.pdf repaired.pdf

# Verify PDF integrity
pdfinfo damaged.pdf

# Extract and rebuild with ghostscript
gs -o repaired.pdf -sDEVICE=pdfwrite damaged.pdf

Output File Size Issues

Problem: Merged PDF is unexpectedly large

Explanation: pdfunite preserves original quality without compression

Solution - Compress with ghostscript:

# Screen quality (low, 72dpi)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen \
   -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf input.pdf

# Ebook quality (medium, 150dpi)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
   -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf input.pdf

# Printer quality (high, 300dpi)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer \
   -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf input.pdf

pdfunite vs pdftk vs ghostscript vs qpdf

Featurepdfunitepdftkghostscriptqpdf
SpeedVery fastFastSlowerFast
Package SizeLess than 1 MB14MB30MB+3MB
SyntaxSimpleModerateComplexModerate
Preserve hyperlinks
Preserve bookmarks
CompressionLimited
Encrypted PDFsLimitedLimited✅ Best
Page manipulation✅ BestLimited✅ Good
Metadata editingLimited
Batch operations
Best forQuick mergesFull editingCompressionEncryption

When to Use Each Tool

Use pdfunite when:

  • Simple concatenation is all you need
  • Speed is critical
  • Working with standard, unencrypted PDFs
  • Automating basic merge operations
  • Hyperlinks aren't important

Use pdftk when:

  • Must preserve hyperlinks and bookmarks
  • Need page-level operations (rotate, remove, reorder)
  • Working with form fields
  • Adding watermarks or stamps
  • Manipulating PDF metadata

Use ghostscript when:

  • Output size must be minimized
  • Converting between PDF versions
  • Rendering PDFs to images
  • Complex transformation operations

Use qpdf when:

  • Handling encrypted PDFs
  • PDF structure manipulation
  • Linearizing PDFs for web viewing
  • Advanced stream compression

Practical Workflow Examples

Organize Scanned Documents

#!/bin/bash
# Organize scanned pages by document type

mkdir -p contracts invoices receipts

# Sort files by type
mv *contract*.pdf contracts/
mv *invoice*.pdf invoices/
mv *receipt*.pdf receipts/

# Merge each category
pdfunite contracts/*.pdf all_contracts_2026.pdf
pdfunite invoices/*.pdf all_invoices_2026.pdf
pdfunite receipts/*.pdf all_receipts_2026.pdf

Create Monthly Archives

#!/bin/bash
# Archive PDFs by month

for month in {01..12}; do
  files=(202601${month}_*.pdf)
  if [ ${#files[@]} -gt 0 ]; then
    pdfunite "${files[@]}" "archive_2026_${month}.pdf"
  fi
done

Combine Book Chapters

#!/bin/bash
# Assemble book from chapter files

chapters=(
  "00_frontmatter.pdf"
  "01_introduction.pdf"
  "02_chapter1.pdf"
  "03_chapter2.pdf"
  "04_chapter3.pdf"
  "05_conclusion.pdf"
  "06_references.pdf"
)

pdfunite "${chapters[@]}" "complete_book_final.pdf"

Frequently Asked Questions

Q: Does pdfunite preserve PDF quality?

A: Yes. pdfunite preserves the original visual quality because it does not recompress images or re-render pages. It rebuilds a new PDF using existing page content, so there is no quality loss, though internal links and bookmarks may not survive.

Q: Can I merge PDFs and images together?

A: No. Convert images to PDF first using img2pdf or ImageMagick's convert, then merge:

img2pdf page1.jpg page2.png -o images.pdf
pdfunite document.pdf images.pdf combined.pdf

Q: Why are my hyperlinks broken after merging?

A: This is a known limitation of pdfunite. Use pdftk instead to preserve internal links.

Q: Can pdfunite merge password-protected PDFs?

A: No. Decrypt them first with qpdf --decrypt or pdftk before merging.

Q: How do I merge PDFs in reverse order?

A: List files in reverse:

pdfunite file3.pdf file2.pdf file1.pdf reversed.pdf

Q: Does pdfunite work on macOS or Windows?

A: Yes via Homebrew on macOS (brew install poppler) or WSL2 on Windows.

Q: Can I automate pdfunite in Python scripts?

A: Yes:

import subprocess

files = ['file1.pdf', 'file2.pdf', 'file3.pdf']
output = 'merged.pdf'

subprocess.run(['pdfunite'] + files + [output], check=True)

Related Poppler Tools

All included in poppler-utils:

  • pdfseparate - Split PDF into individual pages
  • pdfinfo - Display PDF metadata and properties
  • pdftotext - Extract text content from PDFs
  • pdfimages - Extract embedded images
  • pdftoppm - Convert PDF to PPM/PNG/JPEG images
  • pdftohtml - Convert PDF to HTML
  • pdftops - Convert PDF to PostScript

Quick pdfseparate Example:

# Split multi-page PDF
pdfseparate document.pdf page_%03d.pdf

# Extract specific page range
pdfseparate -f 5 -l 10 document.pdf section_page_%d.pdf

Pdfunite Quick Summary

# Basic merge
pdfunite file1.pdf file2.pdf output.pdf

# Merge all PDFs in directory
pdfunite *.pdf combined.pdf

# With full paths
pdfunite /path/to/file1.pdf /path/to/file2.pdf /output/merged.pdf

# Check version
pdfunite --version

# Get help
pdfunite --help

Related Read:


Conclusion

pdfunite excels at what it does: fast, simple PDF merging. While it lacks advanced features like bookmark preservation or page manipulation, its speed and simplicity make it the go-to tool for straightforward concatenation tasks in Linux environments.

For basic merging needs, pdfunite is unbeatable. For complex PDF operations, combine it with other tools in the poppler-utils suite or use specialized alternatives like pdftk and qpdf.

Resources:

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More