Posted 11 months ago. Visible to the public.

Joining PDFs with Linux command line

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.

pdfjam

The pdfjoin binary from pdfjam is probably already installed on your system. Usage:

Copy
pdfjoin one.pdf two.pdf --outfile out.pdf

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

Copy
pdfjoin one.pdf two.pdf --outfile out.pdf --paper a4paper --rotateoversize false

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

PDFtk

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

Copy
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 for more.

ImageMagick (not recommended)

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

Copy
convert one.pdf two.pdf out.pdf

We don't recommend this.

Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Judith Roth
Last edit:
11 months ago
by Arne Hartherz
Keywords:
concat, concatenate
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Judith Roth to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more