← Back to Blog

Merge Multiple PDF Files: Free Online & CLI Methods

Combining multiple PDF files into a single document is one of the most common document tasks. Whether you need to assemble a contract from separate sections, combine monthly reports, or merge scanned pages into a single file, here is every method available - from zero-install browser tools to command-line one-liners.

When You Need to Merge PDFs

The need to combine PDF files comes up constantly in real workflows:

  • Assembling a multi-document proposal (cover letter + resume + portfolio) into one file for submission
  • Combining invoices or receipts for expense reports or tax filing
  • Merging individually scanned pages from a flatbed scanner into a single document
  • Concatenating monthly or quarterly reports into an annual archive
  • Assembling chapters or sections written by different authors into a single manuscript
  • Combining form pages with supporting documents for submission to government or legal systems

The right tool depends on your situation: how many files, how often you need to do it, whether you need to reorder pages, and whether privacy (keeping files off cloud servers) matters.

Method 1: Browser-Based Merger (No Software Required)

For one-off merges, a browser based tool is the fastest approach. Our PDF Merger processes everything locally in your browser using PDF-lib - your files are never uploaded anywhere.

Step-by-Step

  1. Open the SecureBin PDF Merger.
  2. Click "Add Files" or drag and drop your PDF files into the upload area. You can add multiple files at once.
  3. Reorder the files by dragging them into the correct sequence. The order in the list becomes the order in the output document.
  4. Optionally, expand individual files to reorder or exclude specific pages from each document.
  5. Click "Merge PDFs". The combined file is assembled in your browser and downloaded instantly.

The result is a single PDF containing all pages from all input files in the order you specified. Bookmarks, hyperlinks, and most annotations from the original files are preserved.

Privacy note: services like Smallpdf, ILovePDF, and Adobe's online tools upload your files to their servers. For sensitive documents (legal, medical, financial), use a browser based tool that processes files locally, or use the command-line tools described below.

Merge PDFs Free - No Upload Required

Combine unlimited PDF files in your browser. Drag to reorder pages. 100% client side - files never leave your device.

Open PDF Merger

Method 2: pdftk (PDF Toolkit) - Command Line

pdftk is the classic command-line tool for PDF manipulation. It is available on Linux, macOS (via Homebrew), and Windows.

Install pdftk

# macOS
brew install pdftk-java

# Ubuntu / Debian
sudo apt install pdftk

# Windows: download installer from pdflabs.com

Basic Merge

# Merge three files in order
pdftk file1.pdf file2.pdf file3.pdf cat output combined.pdf

# Merge all PDFs in the current directory
pdftk *.pdf cat output combined.pdf

Merge with Page Selection

# Merge pages 1-3 from file1, all of file2, page 5 from file3
pdftk A=file1.pdf B=file2.pdf C=file3.pdf \
  cat A1-3 B C5 output combined.pdf

# Reverse the page order of a file
pdftk input.pdf cat end-1 output reversed.pdf

# Extract only odd pages (for rescanning double-sided documents)
pdftk input.pdf cat 1-endodd output odd_pages.pdf

Handling Password-Protected PDFs

# Provide the owner password to unlock a protected PDF
pdftk secured.pdf input_pw mypassword cat output unlocked.pdf

# Then merge the unlocked version with other files
pdftk unlocked.pdf file2.pdf cat output combined.pdf

Method 3: Ghostscript - Merge and Compress in One Step

Ghostscript can merge PDFs while simultaneously applying compression, which is useful when the source files are large:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
   -dPDFSETTINGS=/ebook \
   -sOutputFile=combined.pdf \
   file1.pdf file2.pdf file3.pdf

The -dPDFSETTINGS=/ebook flag applies compression during the merge. Remove it to get lossless output. See our PDF compression guide for the full explanation of Ghostscript quality settings.

Method 4: Python with pypdf

For scripting, automation, or applications, pypdf (formerly PyPDF2) is the standard Python library for PDF manipulation:

pip install pypdf
from pypdf import PdfWriter

writer = PdfWriter()

# Add all pages from each input file
for filename in ['file1.pdf', 'file2.pdf', 'file3.pdf']:
    writer.append(filename)

# Write the combined output
with open('combined.pdf', 'wb') as output_file:
    writer.write(output_file)

Selective Page Merging with Python

from pypdf import PdfWriter, PdfReader

writer = PdfWriter()

# Add pages 0-2 (0-indexed) from file1
reader1 = PdfReader('file1.pdf')
for page in reader1.pages[:3]:
    writer.add_page(page)

# Add all pages from file2
writer.append('file2.pdf')

# Add only the last page from file3
reader3 = PdfReader('file3.pdf')
writer.add_page(reader3.pages[-1])

with open('combined.pdf', 'wb') as f:
    writer.write(f)

Method 5: macOS Preview (Built-in, No Install)

macOS users have a built-in PDF merger in Preview:

  1. Open the first PDF in Preview.
  2. Open the Thumbnails panel: View → Thumbnails (or Shift+Command+2).
  3. Drag additional PDF files from Finder directly into the Thumbnails panel at the position where you want them inserted.
  4. Drag individual page thumbnails to reorder them.
  5. File → Export as PDF to save the combined document.

This works well for small merges. For batch operations or scripting, use pdftk or Python instead.

Handling Common Problems

Different Page Sizes

When merging PDFs with different page sizes (e.g., A4 and Letter), the output preserves each page's original size. If you need a uniform page size, use Ghostscript with the -sPAPERSIZE=a4 flag, or use Adobe Acrobat's "Normalize Page Size" option before merging.

Fonts Not Rendering Correctly After Merge

This happens when source PDFs reference fonts that are not fully embedded. Run each source PDF through Ghostscript with -dEmbedAllFonts=true before merging to ensure all fonts are embedded. This increases file size slightly but guarantees correct rendering.

Bookmarks and Table of Contents

pdftk preserves bookmarks from individual files but does not create a combined table of contents. To add a master bookmarks structure, use pdftk's update_info operation or use Python's pypdf to programmatically create a bookmark hierarchy.

Use Our Free Tool

For most use cases, the browser tool is the fastest and most private option. Use our free tool here → securebin.ai/tools/pdf-merger/. Add files, drag to reorder, download - done in under a minute.

Frequently Asked Questions

Does merging PDFs reduce quality?

No, not when done correctly. Browser-based tools using PDF-lib and command-line tools like pdftk merge PDFs losslessly - they copy page content streams from the source files without re-encoding images or text. Quality loss only occurs if you use a tool that converts pages to images before merging, or if you apply compression during the merge (like Ghostscript with /screen settings).

Can I merge password-protected PDFs?

You need the password to merge a protected PDF. With pdftk, provide the owner password using the input_pw flag. With Python's pypdf, pass password="yourpassword" to PdfReader(). If you do not have the password, the PDF is protected and you cannot merge it without the original owner's authorization.

How many PDF files can I merge at once?

There is no inherent limit. Browser-based tools are limited by available RAM in your browser tab. For very large merges (hundreds of files or files totaling several GB), command-line tools like Ghostscript or pdftk are more reliable as they do not hold the entire output in memory. pdftk can handle thousands of input files.

Will merged PDFs be searchable?

The merged PDF is searchable if the source PDFs were searchable. Text content is preserved as-is during a lossless merge. If your source PDFs contain scanned images without OCR, the merged result will also not be searchable. To add searchability to scanned PDFs, run them through OCR software (Tesseract, Adobe Acrobat, or an online OCR tool) before merging.

Can I extract specific pages instead of merging everything?

Yes. With pdftk: pdftk input.pdf cat 2-4 7 output extracted.pdf extracts pages 2, 3, 4, and 7 into a new file. With pypdf, iterate over specific page indices and add them with writer.add_page(reader.pages[n]). Our browser based PDF Merger also supports selecting specific pages from each uploaded file before merging.

UK
Written by Usman Khan
DevOps Engineer | MSc Cybersecurity | CEH | AWS Solutions Architect

Usman has 10+ years of experience securing enterprise infrastructure, managing high-traffic servers, and building zero-knowledge security tools. Read more about the author.