Joining PDFs with Linux command line

Updated . Posted . Visible to the public.

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

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.

Judith Roth
Last edit
Judith Roth
Keywords
concat, concatenate
License
Source code in this card is licensed under the MIT License.
Posted by Judith Roth to makandra dev (2019-09-02 12:01)