In the next article we are going to take a look at how we can combine pdf files. On some occasions it may happen that we meet 2 or more PDF files that we need to combine into one to be able to have it all in a single file. This will minimize time wasted trying to find these PDF files which for one reason or another may be in different folders and other directories.
To make this article, I have tried some tools to join or combine PDF files from Ubuntu. I have tried all the tools that we will see in the Ubuntu 18.04 version below, but I imagine that they can be used in other Gnu / Linux distributions.
Combine PDF files
First of all, in a folder called PDFS, I will include 2 PDF documents to work with with them:
- betweenonesandceros-1.pdf
- betweenonesandceros-2.pdf
Using pdfunite
Pdfunite is a tool that can be used to join PDF documents. It is part of the poppler-utils package. This is the reason why when you install poppler, pdfunite is already included. To install this tool we open a terminal (Ctrl + Alt + T) and write:
sudo apt update && sudo apt install poppler-utils
To perform this action, the files to be merged must be in the same directory where pdfunife is running. Using the files I have named above, the command to use would be the following:
pdfunite entreunosyceros-1.pdf entreunosyceros-2.pdf archivo_combinados_pdfunite.pdf
The console will show us a handful of warnings at the exit. These are not worrisome, the files will be merged correctly.
As you can see in the previous screenshot, the output file called combined_file_pdfunite.pdf.
Using pdftk
pdftk is yet another tool that can be used to combine PDF documents on Ubuntu 18.04. To install pdftk in terminal on Ubuntu 18.04, first we are going to add the PPA from which we will install the tool. To do this, we open a terminal (Ctrl + Alt + T) and write:
sudo add-apt-repository ppa:malteworld/ppa
After adding the PPA, in Ubuntu 18.04 the software listing will be updated. We continue installing the pdftk tool with the following command:
sudo apt install pdftk
After the pdftk installation is complete, using our example files, the command to use to combine the PDFs shall be as follows:
pdftk entreunosyceros-1.pdf entreunosyceros-2.pdf cat output archivos_combinados_pdftk.pdf
Using convert
To use the convert command, first we will have to install Imagemagick, if we don't already have it installed, opening a terminal (Ctrl + Alt + T) and using the following command:
sudo apt install imagemagick
Using our example PDF files, the command that we will have to use to combine them will be the following:
convert entreunosyceros-1.pdf entreunosyceros-2.pdf archivos_combinados_convert.pdf
For combine specific pages of PDF files into one file, we will have to pass to the convert command our files with the specific page numbers in brackets. For example, to combine the 5th page of the first document with the 7th and 10th pages of the second document, you would use a command like the following. Let no one forget the number zero. For this the indicated numbers are less than the ones we are interested in.
convert entreunosyceros-1.pdf[4] entreunosyceros-2.pdf[6,9] paginas_combinadas_convert.pdf
With this command it is also possible join page ranges. We could join the first 5 pages of the first file with the first 10 pages of the other. Using our sample files, the command to use would be:
convert entreunosyceros-1.pdf[0-4] entreunosyceros-2.pdf[0-9] rango_paginas_combinadas_convert.pdf
Using Ghostscript
We can also use ghostscript (gs) to join PDF documents on Ubuntu 18.04. To install it, in a terminal we write:
sudo apt install ghostscript
Now we will see an example of using ghostscript to combine our two sample PDF documents. The command to use will be:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Ghostscript-archivos-combinados.pdf -dBATCH entreunosyceros-1.pdf entreunosyceros-2.pdf
Using pdfsam
pdfsam is a simple, intuitive and easy to use GUI tool which is used to merge, split, rotate, edit and sign PDF documents. In this example, we are going to use the option to combine PDF documents in Ubuntu 18.04. But first, we will install the dependencies necessary:
sudo apt install openjdk-8-jre libopenjfx-jni libopenjfx-java openjfx
After successful installation, we will define the variable JAVA_HOME in the path / etc / environment using our favorite editor.
vim /etc/environment
Inside the file, we will add the following line:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
After saving and exiting, we reload the edited file:
source /etc/environment
Then we will download the .deb file from the official site from pdfsam:
wget https://github.com/torakiki/pdfsam/releases/download/v3.3.6/pdfsam_3.3.6-1_all.deb
Once downloaded, we can install the file using dpkg:
sudo dpkg -i pdfsam_3.3.6-1_all.deb
For start pdfsam, in a terminal we write its name:
pdfsam
When we want to combine documents, we will click on 'Combine'. On the screen that will be shown, you will have to drag and drop the files in the section dedicated to these:
If you need it, do not hesitate to specify other attributes in the 'Configure join' section. The combination will start when you click on 'Run', located at the bottom. A 'ding' sound will notify us that the process is complete.
A shame because it looked very good. pdfsam cannot be used in Ubuntu 18, it has a bug regarding Sejda and cannot create the combined file. To try another! I don't know which one to choose ...
Very good post, I only mention that when you have images you want to make a PDF of several of them, Ampare Images to PDF works for me in Ubuntu 18.04.
There is an error with ImageMagick you have this message attempt to perform an operation not allowed by the security policy `PDF '@ error / constitute.c / IsCoderAuthorized / 408.
Here I leave the link to the solution https://stackoverflow.com/a/53180170
But I have noticed that with ImageMagick the quality is lowered
I liked pdfunite, quality is lost ... and if it is lost, I don't notice it
Thank you very much, I served the first one and that's it! 😀