There are a lot of software in Windows to merge PDF files but how can we do the same in Ubuntu?
-
I found this link – Grijesh Chauhan Jun 05 '14 at 09:18
15 Answers
pdftk
To merge two pdf files, file1.pdf
and file2.pdf
:
pdftk file1.pdf file2.pdf cat output mergedfile.pdf
More info available hereWay Back Machine.
To install, run:
sudo snap install pdftk
-
14pdftk is buggy - https://bugs.launchpad.net/ubuntu/+source/pdftk/+bug/779908.
gs might be slow, but does the work perfectly [IgnitE's answer]
– Pushpak Dagade Apr 03 '13 at 11:05 -
@PushpakDagade ghostscript messes up with annotations, particularly comments that have been checked (check box ticked with checkmark), will no longer have this checkmark. I am not aware of a way around this. Also, if you merge PDF v1.5 + 1.6, output will be 1.4 by default. That is strange behavior. – Jonathan Komar May 19 '16 at 14:12
-
This is beautiful. Working pretty fine on 14.04.5 LTS and we can merge PDF's with different page size/orientation. Produces high quality and low size files. Thank you! – Geppettvs D'Constanzo Sep 03 '17 at 20:22
-
4pdftk has an unusual usage where commands
cat
andoutput
follow variadic input arguments and followed again by an output argument. – Jeff Puckett Nov 07 '17 at 03:47 -
8
-
2
-
@Max do you know what is the difference between the two snaps at https://snapcraft.io/search?category=&q=pdftk ? – Nicolas Raoul Sep 01 '18 at 14:55
-
3FYI:
sudo snap install pdftk
- there is no release candidate for the aptitude app anymore, it was deprecated by the author, who created the snap package. – GrayedFox Oct 19 '18 at 14:30 -
-
-
-
-
1
-
6It works great. To install on Ubuntu 20.04 LTS do:
sudo apt install pdftk-java
– michael Jun 09 '20 at 08:27 -
-
2
-
-
1
sudo snap install pdftk
can be used in Ubuntu 20.04 and pdftk is accepting "*.pdf" as a valid parameter. – Celal Ergün May 27 '21 at 07:55 -
https://askubuntu.com/questions/1028522/how-can-i-install-pdftk-in-ubuntu-18-04-and-later it exists as
pdftk-java
and can be used aspdftk
– qwr Aug 18 '21 at 01:02 -
-
PDF Arranger formerly known as PDF-Shuffler.
If you want a tool with a simple GUI, try pdfarranger. It allows for merging of PDFs as well as rearranging and deleting pages. For batch processing and/or more complicated tasks, pdftk is of course more powerful.
To install PDF Arranger in Ubuntu 20.04 and later open the terminal and type:
sudo apt install pdfarranger

- 114,770

- 41,762
-
-
On 12.04, pdfshuffler always complains that there are "too many values to unpack", making it unusable. – despens Apr 12 '13 at 12:15
-
-
10
-
I used to use pdftk for this behavior. Thanks for the PDF Shuffle reference. It looks really slick. – csgeek Dec 11 '14 at 15:51
-
1
-
This is the quickest and easiest solution. Thank you! (Ubuntu 14.04 64-bit) – The Unknown Dev Mar 12 '16 at 21:25
-
This works well in many cases but I noticed that it stripped out hyperlinks. Using pdftk does not strip out hyperlinks. So, if there is any complexity to the PDFs that you are concatenating, I would use the command line tool; at the very least, thoroughly test your output file. – revnoah Apr 16 '16 at 21:47
-
just tried for one case but I got an error "multiple definitions in dictionary" so it could not create an output. their issue tracking on that is open for quite some time without resolution so I assume the project is not very active, would not recommend! – SCBuergel Apr 28 '16 at 22:30
-
2
-
-
-
2Tried PdfShuffler 0.6.0 (
apt-get install pdfshuffler
) on Ubuntu 14.0 64-bit and it works with one caveat - It has problem dealing with some special characters in the filename (in my case pdfshuffler cannot load filename with#
) – Tzunghsing David Wong Jan 24 '19 at 22:28 -
-
-
Just used it on 19.10, to merge and crop a series of pdf, worked like a charm. – Will59 Mar 09 '20 at 10:32
-
12This tool has been renamed to
pdfarranger
as of Ubuntu 20.04. You can still installpdfshuffler
via apt, but it is just an empty pointer topdfarranger
which is also the command you'll need after install. – Carl Zulauf Aug 03 '20 at 21:29 -
This is crashing in ubuntu 16.04. I have tried pdftk which is not gui based application – Gireesh Mar 10 '21 at 10:04
-
@CarlZulauf can you provide a link to documentation showing this renaming of pdfarranger? I'm not seeing any evidence of this in apt and not able to get pdfshuffler to work at that. – topher217 Apr 07 '22 at 09:06
-
@topher217 APT will tell you pdfshuffler is just pdfarranger. On Ubuntu 20.04 try
$ apt show pdfshuffler
and look closely. – Carl Zulauf Apr 12 '22 at 16:40 -
@CarlZulauf maybe you or I have a manually added an apt repo to pdfshuffler? I'm not seeing anything. Here is the pastebin of the output from
apt show pdfshuffler
. This is after runningsudo apt update
just in case. I'm on Ubuntu 20.04 withapt -v
returningapt 1.6.14 (amd64)
. The only docs on pdfarranger I found were the github repo which doesn't appear to give any apt based instructions for installation but rather via pip. – topher217 Apr 13 '22 at 01:48 -
Ghostscript is a package (available by default in Ubuntu) that enables you to view or print PostScript and PDF files to other formats, or to convert those files to other formats.
To use Ghostscript to combine PDF files, type something like the following:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf file1.pdf file2.pdf
Here is a brief explanation of the command:
gs starts the Ghostscript program.
-dBATCH once Ghostscript processes the PDF files, it should exit.
If you don't include this option, Ghostscript will just keep running.
-dNOPAUSE forces Ghostscript to process each page without pausing for user interaction.
-q stops Ghostscript from displaying messages while it works
-sDEVICE=pdfwrite
tells Ghostscript to use its built-in PDF writer to process the files.
-sOutputFile=finished.pdf
tells Ghostscript to save the combined PDF file with the specified name.
-dAutoRotatePages=/None
Acrobat Distiller parameter AutoRotatePages controls the automatic orientation selection algorithm: For instance: -dAutoRotatePages=/None or /All or /PageByPage.
Your input files don't even need to be PDF files. You can also use PostScript or EPS files, or any mixture of the three.
There is a lot you can do with Ghostscript. You can read its documentation for more details.
-
3True, but it's incredibly slow. I just tried concatenating 45 x 400K, single-page PDFs.
pdftk
took 0m0.484s,gs
took 1m32.898s (that's almost 200x slower) The file fromgs
was about 21% smaller though. – aidan Mar 22 '13 at 06:47 -
7this command also works if you use a wildcard for the list of files to be combined. for example, replace
file1.pdf file2.pdf
withfile*.pdf
– Antonios Hadjigeorgalis May 29 '14 at 13:58 -
2For me
gs
worked with some "non conformant" PDFs wherepdftk
would just run forever. – ntc2 Dec 09 '14 at 04:37 -
-
1Use
-dPDFSETTINGS=/prepress
option from quality improvement. All thanks due to the original contributor – Mohnish Apr 20 '16 at 11:58 -
14@AntoniosHadjigeorgalis Just for reference and good understanding: that's not the command supporting wildcards, that's actually the shell replacing
file*.pdf
withfile1.pdf file2.pdf
before passing the arguments to the command. – Midgard Jun 15 '16 at 10:15 -
4I merged ~20 small pdfs into a single file in a fraction of a femto-second with
gs
. No need to download 70MB ofpdftk
. Thanks @ignite! – Campa Jul 15 '16 at 12:37 -
+1 Worked with encrypted pdfs as well (these annoying files that can be viewed but not merged without a password). – Sir_FZ Sep 28 '16 at 11:57
-
2This worked fine for me on Ubuntu 16.04 with no extra downloads. Merging 4 pages was almost instantaneous. – Paolo Mioni Oct 25 '16 at 06:24
-
@aidan sounds like gs rerenders the files instead of just copying the content. This might be a good thing if you want a distiller like workflow – Thorbjørn Ravn Andersen Nov 07 '16 at 13:27
-
1The
gs
method will break the href and url link in the pdf created by pdflatex. pdfshuffler can keep the link. – HD189733b Dec 16 '18 at 00:35 -
I'm using this to concatenate 3 files, and
gs
inexplicably takes the title of one of them and uses it as the title of the new document (shown in the title bar by the PDF viewer). I wonder if the new title could be specified explicitly. – MWB Mar 28 '21 at 21:58 -
This works:
gs -dBATCH -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
, no need for the-q
and-dnopause
which did not help to output more silent. No need fordAutoRotatePages
. – Timo Apr 24 '21 at 18:40 -
Worked really well, I used
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf *
(with the wildcard). Great, and open source. Thanks! – Giovanni Bassi Feb 15 '22 at 22:39
You also also use pdfunite to merge pdf documents :
pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf
To install pdfunite
if it is not installed already, run:
sudo apt-get install poppler-utils
-
21WARNING: An existing file
out.pdf
will be overwritten without warning, sopdfunite *.pdf
won't work as expected. – krlmlr Dec 04 '14 at 15:02 -
2
-
1Fair enough,
cp
also overwrites last argument without warning. This is just for rushing users (like myself) -- I was lucky I had a backup of the file in question... – krlmlr Dec 04 '14 at 15:08 -
2Upvote: This is a simple command-line tool without a click-and-drool GUI like many of the other answers here. It nicely encapsulates the complexities of the (largely equivalent) GhostScript solution. – tripleee Apr 13 '15 at 14:28
-
2This is also very fast. Does the job well. On a very slow server (aws t1.micro), gs takes 9 secs, pdftk takes 4 secs and this pdfunite takes 0.9 secs for merging two files! – rsmoorthy Jul 15 '15 at 19:49
-
1
-
1To get this on Ubuntu 16.04, run
sudo apt-get install poppler-utils
. You'll then be able to typepdfunite --help
and see that it's installed. – Volomike Jun 12 '17 at 22:38 -
1Interesting:
pdfunite
is available by default in Ubuntu MATE 20.04. (I certainly didn't install it...) – Frank N Jun 22 '21 at 08:28 -
1
A very nice solution is PDFChain. It's GUI is a frontend of PDFTK where you can merge, split or even add some background to your PDF files.
-
This is the best answer. It works perfectly, regardless of the Ubuntu version. – Paulo Coghi Feb 01 '17 at 17:33
-
-
-
1
-
@user2413 that's a snap store, not the only source for software in Ubuntu. Trying to search in
apt
didn't give any results either though :/ – jena Sep 05 '19 at 13:54 -
1
An alternative approach is to use Latex as explained in this post (without root access assuming that you have pdflatex installed): https://tex.stackexchange.com/questions/8662/merge-two-pdf-files-output-by-latex
This is useful in case you do not have the mentioned tools nor root privileges, but you do have pdflatex.
I copy the tex code below to merge file1.pdf
and file2.pdf
. Create a file called output.tex
and put:
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=-]{file1}
\includepdf[pages=-]{file2}
\end{document}
And to compile, simply use: pdflatex output.tex
The merged file will be named as output.pdf
.
-
This is the best approach because the result will always be there, no bugs – Billal Begueradj Sep 14 '20 at 09:04
-
1
Give PDFMod a try, it’s from the GNOME project:
https://wiki.gnome.org/Apps/PdfMod
sudo apt install pdfmod
-
-
1it did merging in the past, now it's just crashing, I used the pdfshuffler instead and it worked great – jena Dec 11 '18 at 21:41
Use pdfsam http://www.pdfsam.org/ it's very good for splitting and merging pdfs
sudo apt install pdfsam

- 41,766

- 111
- 1
- 3
-
Used it under 19.10 to merge file: simple interface, a few options, works very well. But other features such as crop are premium options.
sudo apt-get install pdfshuffler
did the trick :-) – Will59 Mar 09 '20 at 10:35
I use pdfseparate to extract specific pages from big pdf file:
pdfseparate -f 156 -l 157 input.pdf output_%d.pdf
pdfseparate -f 1 -l 2 input.pdf output_%d.pdf
and aftewards I join them all via command:
pdfunite $(ls -v output_*.pdf | tr '\n' ' ') out$(date +%Y-%m-%d_%H_%M_%S ).pdf
This joins:
output_1.pdf output_2.pdf output_156.pdf output_157.pdf
into:
out2014-12-14_23_25_36.pdf
May be there is an easier way how to cope... :-)
Installation instructions:
sudo apt install poppler-utils

- 41,766

- 990
- 9
- 20
-
2The process substitution is superfluous and potentially even harmful. A correct an much simpler command line is
pdfunite output_*.pdf out$(date +%Y-%m-%d-%H_%M_%S).pdf
but it lacks the ordering ofls -v
. An obvious and trivial fix is to name your files so that they naturally sort in the order you want to include them. If you absolutely wantls -v
, you can at least lose the pipe totr
, which accomplishes nothing here. – tripleee Apr 13 '15 at 14:24
You can use pdftk to merge and modify PDF documents in general. Alternatively there's an online service to do just that: http://www.pdfmerge.com/

- 235
You can see use the free and open source pdftools (disclaimer: I am the author of it).
It is basically a Python interface to the Latex pdfpages
package.
To merge pdf files one by one, you can run:
pdftools --input-file file1.pdf --input-file file2.pdf --output output.pdf
To merge together all the pdf files in a directory, you can run:
pdftools --input-dir ./dir_with_pdfs --output output.pdf

- 1,084
- 1
- 11
- 28
Here is my approach:
- I wanted it to be easily accessible so I created a right-click shortcut in Nautilus (see https://help.ubuntu.com/community/NautilusScriptsHowto)
- I wanted it to be very quick so I used pdfunite
- pdfunite only accepts the filepaths in the middle of the command so I had to scratch my head to manage the spaces in the filepaths. So I took the assumption that all filepaths will start with "/home/" and end with ".pdf"
Here is the result:
#!/bin/sh
CLEANED_FILE_PATHS=$(echo $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS | sed 's,.pdf /home/,.pdf\\n/home/,g')
echo $CLEANED_FILE_PATHS | bash -c 'IFS=$'"'"'\n'"'"' read -d "" -ra x;pdfunite "${x[@]}" merged.pdf'
Juste paste this script in
/home/your_username/.local/share/nautilus/scripts
and name it "merge_pdfs.sh" (for example). Then make it executable (right-click on merge_pdfs.sh -> Permissions tab -> tick "Allow executing file as a program"
So now to merge pdf files, you just have to select them -> right click -> scripts -> merge_pdfs.sh and it will create a "merged.pdf" file in the same directory
Hope it helps!

- 395
I did not find pdfarranger
in snap
(Ubuntu 22.04).
Thus I installed sudo snap install pdfmerger
.
This tool also has a simplistic GUI and worked perfectly for me.

- 221
qpdf
This also worked for me:
sudo apt install qpdf
qpdf --empty --pages in1.pdf in2.pdf in3.pdf -- out.pdf
For some encryption related reason which I don't fully understand pdftk in1.pdf in2.pdf in3.pdf cat output out.pdf
, pdftk was failing with:
Error: Invalid PDF: unknown.encryption.type.r
on certain PDFs I downloaded, even though they didn't require a password to open.
Related threads:
Source code: https://github.com/qpdf/qpdf
License: Apache.
Project description:
QPDF is a command-line tool and C++ library that performs content-preserving transformations on PDF files. It supports linearization encryption, and numerous other features. It can also be used for splitting and merging files, creating PDF files (but you have to supply all the content yourself), and inspecting files for study or analysis. QPDF does not render PDFs or perform text extraction, and it does not contain higher-level interfaces for working with page contents. It is a low-level tool for working with the structure of PDF files and can be a valuable tool for anyone who wants to do programmatic or command-line-based manipulation of PDF files.
Tested on Ubuntu 23.10, pdftk 3.3.3, qpdf 11.5.0.

- 28,474