Sometimes, you may have 2 or more PDF files that you need to combine or merge into one so that you can have everything in one place. This will minimize time wasted trying to look for your PDF files which may be in different folders and other directories.
In this guide, we learn how to merge pdf files on Ubuntu using GUI and terminal.
1. Using pdfunite
Pdfunite is a handy tool that can be used for merging two or more PDF documents. It is part of poppler-utils package, so when you install poppler utils, you end up with pdfunite.
First, update the system:
apt update
To install pdfunite on Ubuntu, we’ll install the poppler-utils package:
apt install poppler-utils
In the downloads folder, I have 2 PDF documents
- linux_for_beginners.pdf
- linux_for_beginners_2.pdf
We are going to merge them using pdfunite command.
To merge the PDF documents, the syntax will be as shown
pdfunite file1.pdf file2.pdf merged_output.pdf
Using our files as shown earlier, the command will be
pdfunite linux_for_beginners.pdf linux_for_beginners_2.pdf merged_output.pdf
You will get the following warning in the output, but don’t worry. The files have already been merged.
As you can see, the output file merged_output.pdf has been created
Note: Files to be merged need to be in the same directory where pdfunite is executed
2. Using pdftk
Pdftk is yet another tool that can be used to merge PDF documents in Ubuntu.
Update your Ubuntu System
apt update
After successfully updating your system, install the pdftk tool as shown below
apt install pdftk
After the installation of pdftk is complete, you can now invoke the pdftk command to merge files. The syntax is as shown
pdftk file1.pdf file2.pdf cat output merged_output.pdf
Using our earlier files, the command will be as shown
pdftk Linux_for_beginners.pdf Linux_for_beginners_2.pdf cat output merged_output.pdf
3. Using Ghostscript
We can also use ghostscript (gs) to merge PDf documents in Ubuntu 18.04
apt install ghostscript
Example of using ghostscript to merge 2 PDF documents
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combine.pdf -dBATCH file1.pdf file2.pdf
In the above example, let's expound further on the attributes
-sOUTPUTFILE denotes the output file
-dBATCH denotes the pdf documents to be merged
Using our documents earlier, the command will be
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combine.pdf -dBATCH Linux_for_beginners.pdf Linux_for_beginners_2.pdf
Output
GPL Ghostscript 9.22 (2017-10-04)
Copyright (C) 2017 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 29.
Page 1
Page 2
Loading NimbusSans-Regular font from /usr/share/ghostscript/9.22/Resource/Font/NimbusSans-Regular... 5056280 3684544 3235592 1819445 3 done.
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8
4. Using pdfsam
Pdfsam is a simple, intuitive, and easy-to-use GUI tool that is used to merge, split, rotate, edit and sign PDF documents. In this example, we are going to use the tool to merge PDF documents in Ubuntu 18.04.
But first, let's install prerequisites packages. From version 4, Java is bundled with the application.
apt install openjdk-8-jre libopenjfx-jni libopenjfx-java openjfx
After successful installation, define the JAVA_HOME variable in /etc/environment path using your favorite editor.
nano /etc/environment
Append the following line.
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
Save and Exit
reload the file
source /etc/environment
Next, download the Debian package file from pdfsam's official site
wget https://github.com/torakiki/pdfsam/releases/download/v3.3.6/pdfsam_3.3.6-1_all.deb
Once downloaded, install the deb file using the dpkg command as shown.
dpkg -i pdfsam_3.3.6-1_all.deb
To start pdfsam, run
pdfsam
To merge documents, click on 'Merge' and drag and drop the files to be merged in the section provided.
Feel free to specify other attributes in the 'Merge Settings' section and once done click on the 'Run' icon located at the bottom. Once done, you'll hear a 'ding' sound notifying you that the merging process is complete.
Conclusion
Merging PDF files on Ubuntu is very easy and straightforward. Give it a try and let us know how it went.
Thanks for reading, leave your feedback and suggestions in the below comment section.
Comments