Read more

Joining PDFs with Linux command line

Deleted user #4117
September 02, 2019Software engineer

There are several ways to merge two (or more) PDF files to a single file using the Linux command line.

Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show archive.org snapshot

If you're looking for graphical tools to edit or annotate a PDF, we have a separate card for that.

PDFtk is a great toolkit for manipulating PDF documents. You may need to install it first (sudo apt install pdftk).
Merging multiple files works like this:

pdftk one.pdf two.pdf cat output out.pdf

Unlike pdfjam, PDFtk should not mess with page sizes but simply joins pages as they are.

See pdftk --help or the PDFtk examples page Show archive.org snapshot for more.

pdfjam

This is another option. You may need to install it first: sudo apt install texlive-extra-utils (has many dependencies).

Usage:

pdfjam --outfile out.pdf one.pdf two.pdf

Pages from joined documents might be rotated. To avoid this, call it like this:

pdfjam --outfile out.pdf --fitpaper true --paper a4paper --rotateoversize false  one.pdf two.pdf

For a list of availble options use pdfjam --help.

You could also use ImageMagick's convert, but this will raster vector contents and usually result in lower quality at higher file size:

convert one.pdf two.pdf out.pdf

We don't recommend this.

Posted to makandra dev (2019-09-02 14:01)