How To Merge PDF Files In Command Line On Linux
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. In this brief guide, we are going to see how to merge the two or more PDF files. It’s not that difficult. Read on.
Merge PDF Files In Command Line On Linux
We can do it in two ways.
Method 1: 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.
Let us install pdftk.
In Arch LInux and derivatives:
PDFtk is available in the AUR. You can install it using any AUR helper programs such as Yay.
$ yay -S pdftk
In Debian, Ubuntu and derivatives:
$ sudo apt-get install pdftk
On CentOS, Fedora, Red Hat:
First, Install EPEL repository:
$ sudo yum install epel-release
$ sudo dnf install epel-release
Then install PDFtk application using command:
$ sudo yum install pdftk
$ sudo dnf install pdftk
Now, let us merge some pdf files and made it a single file.
I have three pdf files namely file1.pdf, file2.pdf, file3.pdf in my current working directory. I want to merge them into a single file called outputfile.pdf. So, I ran the following command from the Terminal:
$ pdftk file1.pdf file2.pdf fiel3.pdf cat output outputfile.pdf
Alternatively, you can run:
$ pdftk *.pdf cat output outputfile.pdf
This command will merge all pdf files in the current directory into a single file.
Method 2: 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.
That’s it. You know now how to split a pdf file into many and how to merge many PDF files into a single file. As you can see in this guide, it is not that difficult. You can do this in couple minutes.
If you know any other methods or commands to do this, feel free to let us know in the comment section below. I will be here with another interesting guide soon. Until then, stay tuned with OSTechNix.