Note: All three methods of merging PDF files via the command line have been demonstrated on Linux Mint 20.
Methods of Merging the PDF Files on the Command Line:
For using the “pdftk” utility for merging PDF files via the command line in Linux Mint 20, we will go through the following series of steps:
We have two PDF files in our Home directory named “PDF1.pdf” and “PDF2.pdf”. These files are highlighted in the image shown below:
Double click on the first file to view its content, as shown in the following image:
Now double click on the second file to view its content as well as shown in the image below:
Our goal is to merge these two files for which we will launch our Linux Mint 20 terminal by clicking on its icon as shown in the following image:
Now we have to install the “pdftk” utility by running the following command in our terminal:
$ sudo apt-get install pdftk
Since you are installing a new package on your Linux system, therefore, your terminal will ask you for a confirmation, which you can provide by typing “Y” in your terminal and then pressing the Enter key as shown in the image below:
Once the “pdftk” package has been successfully installed on your system, your terminal will hand you over the control back so that you can easily execute the next commands as shown in the following image:
Now when you are all set to use the “pdftk” package to merge your files, you have to execute the below-mentioned command to achieve this goal:
$ pdftk PDF1.pdf PDF2.pdf cat output PDF3.pdf
Here, you can mention as many PDF files before the “cat” keyword that you want to merge separated by a space. The file name followed by the “output” keyword will be the name of a newly created PDF file, which will be an integrated version of all the files that are mentioned before the “cat” keyword. It means that running this command will create a new PDF file named “PDF3.pdf” which will have the merged contents of both the files “PDF1.pdf” and “PDF2.pdf”.
After running this command, you can verify if a merged PDF file has been created or not by going to your Home directory. Here, you will be able to find “PDF3.pdf” as highlighted in the following image:
Now double click on this newly created PDF file to ensure if it has the merged contents of “PDF1.pdf” and “PDF2.pdf” or not as shown in the images below:
Method # 2: Modified Usage of the “pdftk” Utility:
As we have already mentioned in the name of this method that it is simply a modified version of the “pdftk” method; therefore, we do not need to install any new package this time. This method is used when you want to merge all the PDF files present in any directory, and you want to save yourself from the effort of mentioning the names of all those files separately. This can be done by running the following command in your terminal:
$ pdftk *.pdf cat output PDF3.pdf
Here, the “*” symbol before the PDF extension indicates that you want to merge all the PDF files present in the current directory, whereas PDF3.pdf is the output file where all of your PDF files will be merged. After running this command, you can verify its output in the same manner as we did in the method above.
Method # 3: Using the “poppler” Utility:
This is another method of merging PDF files in Linux Mint 20 which can be used as follows:
First, you need to install the “poppler” utility with the following command:
$ sudo apt-get install poppler-utils
Once this command finishes its execution, the “poppler” utility will be installed on your Linux Mint 20 system as shown in the image below:
After installing this utility, you can use it to merge files via the terminal in the following manner:
$ pdf unite PDF1.pdf PDF2.pdf PDF3.pdf
Here, all the PDF files except for the last one are the ones that you want to merge, whereas the last one indicates the new output file. After running this command, a new PDF file named “PDF3.pdf” will be created that will be an integrated version of the files mentioned before it, and it can be verified in the same manner as explained above.
By choosing any method of your preference from the ones discussed in this article, you can easily merge two or more PDF files via the command line while using Linux Mint 20. These three methods are, in fact, extremely convenient ways of merging the PDF files and that too very quickly.