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 book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
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)