Read more

Joining PDFs with Linux command line

Judith Roth
September 02, 2019Software engineer at makandra GmbH

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

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
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 by Judith Roth to makandra dev (2019-09-02 14:01)