Home Command line utilities How To Merge PDF Files In Command Line On Linux

How To Merge PDF Files In Command Line On Linux

By sk
Published: Last Updated on 13863 Views

We already have covered how to split or extract particular pages from a PDF file in Linux using pdftk utility a while ago. That tutorial described how to extract a page range or a part of a PDF file in Linux. Today, we will see how to merge two or more PDF files using PDFtk and Poppler applications in Linux.

First, we will discuss how to combine PDF files or merge PDF files from commandline using Pdftk tool.

1. Merge PDF Files In Command Line On Linux Using pdftk

PDFtk is free graphical tool that can be used to split or merge PDF files. It is available as free and paid versions. You can use it either in CLI or GUI mode.

PDFtk is available in the default repositories of most Linux distributions. Let us install pdftk.

Install PDFtk in Arch LInux and derivatives:

PDFtk is available in the AUR. You can install it using any AUR helper programs such as Paru or Yay.

$ paru -S pdftk

Or,

$ yay -S pdftk

Install PDFtk In Debian, Ubuntu and derivatives:

$ sudo apt-get install pdftk

Install PDFtk On CentOS, Fedora, Red Hat:

First, Install EPEL repository:

$ sudo yum install epel-release

Or

$ sudo dnf install epel-release

Then install PDFtk application using command:

$ sudo yum install pdftk

Or

$ sudo dnf install pdftk

Now, let us merge some pdf files and made it a single file.

I have three pdf files named file1.pdf, file2.pdf, and file3.pdf in my current working directory. I want to merge them into a single file called outputfile.pdf.

To merge the above three PDF files into one, run the following command from the Terminal:

$ pdftk file1.pdf file2.pdf fiel3.pdf cat output outputfile.pdf

Alternatively, you can use wildcards to merge all files that has .pdf extension and merge into one file like below:

$ pdftk *.pdf cat output outputfile.pdf

This command will merge all pdf files in the current directory into a single file.

2. Merge PDF Files In Command Line On Linux Using Poppler

Poppler is a PDF rendering library based on the xpdf-3.0 code base.

To install Poppler on Arch Linux based distributions, run:

$ sudo pacman -S poppler

On Debian, Ubuntu, Linux Mint:

$ sudo apt-get install poppler-utils

On RHEL, CentOS, Fedora:

$ sudo yum install poppler-utils

Once Poppler installed, run the following command to merge the pdf files in the current working directory.

$ pdfunite file1.pdf file2.pdf file3.pdf outputfile.pdf

The above command will merge file1.pdf, fiel2.pdf and file3.pdf files into a single file called outputfile.pdf.

Conclusion

You know now how to split a pdf file into many parts and how to merge many PDF files into a single file using PDFtk and Poppler tools in Linux. As you can see in this guide, combining or merging PDF files in Linux is not that difficult. You can do this in couple minutes.

Resources: 

You May Also Like

5 comments

Rizwan Mohammed December 8, 2016 - 2:54 pm

Good tips, thank you for your help.

Reply
Carlos Samey April 14, 2019 - 6:46 pm

Thank you for these instructions, really helpful!! I always use Acethinker PDF Converter to merge several PDF files into one PDF, it’s free and it works pretty well for me. Share it here as an alternative solution.

Reply
Aditya June 25, 2019 - 5:07 am

Poppler worked nicely for me. Thanks for the tip!

Reply
Leandro Gado November 5, 2019 - 1:51 am

Good tips, but the best is PDF-Shuffler, available freely in the standard repos

Reply
sk November 5, 2019 - 12:35 pm

Thanks for the heads up. I never heard about PDF-Shuffler. I will look into it soon.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More