How to merge several PDF files?
Solution 1
PDF Arranger (install), 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.
Solution 2
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
Solution 3
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.
Solution 4
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
Solution 5
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.
Related videos on Youtube
Deependra Solanky
I am from India, working on Microsoft Technologies like ASP.NET, SQL Server. I like to read new things about technology on internet on daily basis via Google Reader. I like open source and as a result have some knowledge of PHP/Ruby on Rails/Python. If Microsoft had not introduced ASP.NET MVC one year back, there were chances of me jumping into non-microsoft camp.
Updated on September 17, 2022Comments
-
Deependra Solanky over 1 year
There are a lot of software in Windows to merge PDF files but how can we do the same in Ubuntu?
-
Grijesh Chauhan almost 10 yearsI found this link
-
-
vishal about 12 yearsI tried this - it didn't work on 10.04
-
aidan about 11 yearsTrue, 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. -
Pushpak Dagade about 11 yearspdftk is buggy - bugs.launchpad.net/ubuntu/+source/pdftk/+bug/779908. gs might be slow, but does the work perfectly [IgnitE's answer]
-
Swastika Srivastava about 11 yearsOn 12.04, pdfshuffler always complains that there are "too many values to unpack", making it unusable.
-
user1251007 over 10 yearsFor me it works under 12.04 64-bit, pdfshuffler version 0.6.0
-
Zlatty over 10 yearsInstalls and works like a charm on 14.04. Thanks a bunch!!
-
Antonios Hadjigeorgalis about 10 yearsthis 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
-
krlmlr over 9 yearsWARNING: An existing file
out.pdf
will be overwritten without warning, sopdfunite *.pdf
won't work as expected. -
BЈовић over 9 years@krlmlr You can always put the output into another directory.
-
ntc2 over 9 yearsFor me
gs
worked with some "non conformant" PDFs wherepdftk
would just run forever. -
csgeek over 9 yearsI used to use pdftk for this behavior. Thanks for the PDF Shuffle reference. It looks really slick.
-
tripleee about 9 yearsThe 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 about 9 yearsUpvote: 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.
-
rsmoorthy almost 9 yearsThis 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!
-
The Unknown Dev about 8 yearsThis is the quickest and easiest solution. Thank you! (Ubuntu 14.04 64-bit)
-
Dave about 8 yearsThis 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.
-
Mohnish about 8 yearsUse
-dPDFSETTINGS=/prepress
option from quality improvement. All thanks due to the original contributor -
Jonathan Komar about 8 years@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.
-
Midgard almost 8 years@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. -
user643722 almost 8 yearsThis is also available under Cygwin.
-
Fidel Pérez Menéndez almost 8 yearsI 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! -
Sir_FZ over 7 years+1 Worked with encrypted pdfs as well (these annoying files that can be viewed but not merged without a password).
-
Paolo Mioni over 7 yearsThis worked fine for me on Ubuntu 16.04 with no extra downloads. Merging 4 pages was almost instantaneous.
-
Sanjay Manohar over 7 yearsAlso works great on 16.04.1
-
vaquito over 7 years@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
-
Paulo Coghi over 7 yearsThis is the best answer. It works perfectly, regardless of the Ubuntu version.
-
my account_ram about 7 yearsWorked on Ubuntu 14.04 without hassle!
-
Volomike almost 7 yearsTo 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. -
Geppettvs D'Constanzo over 6 yearsThis 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!
-
COil over 6 yearsGave it a try and works well on 17.04. Very easy to use for basic merge.
-
Jeff Puckett over 6 yearspdftk has an unusual usage where commands
cat
andoutput
follow variadic input arguments and followed again by an output argument. -
orschiro over 6 yearsWorks great on Ubuntu 18.04!
-
Ruthvik Vaila about 6 yearsThis doesn't work for combining encrypted transcripts.
-
Nicolas Raoul about 6 yearsThe package seems to have been removed in 2018.04.
-
user2413 almost 6 years
-
user2413 almost 6 yearsdoes not do merging.
-
Max almost 6 years@NicolasRaoul I just downloaded it as a snap install.
-
Nicolas Raoul over 5 years@Max do you know what is the difference between the two snaps at snapcraft.io/search?category=&q=pdftk ?
-
GrayedFox over 5 yearsFYI:
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. -
jena over 5 yearsit did merging in the past, now it's just crashing, I used the pdfshuffler instead and it worked great
-
HD189733b over 5 yearsThe
gs
method will break the href and url link in the pdf created by pdflatex. pdfshuffler can keep the link. -
Tzunghsing David Wong over 5 yearsTried 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#
) -
jena over 4 years@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 :/ -
cipricus over 4 years@GrayedFox in 18.04
-
cipricus over 4 years@NicolasRaoul in 18.04
-
Bas Swinckels over 4 yearsVersion 0.6.0 works like a charm on 18.04
-
Flimm over 4 yearsHow is this installed in newer Ubuntu versions?
-
Flimm over 4 yearsIt would be better if these were separate answers so that they could be upvoted separately and edited separately.
-
Flimm over 4 yearspdftk is mentioned in this answer: askubuntu.com/a/2802/2355
-
Flimm over 4 years@NicolasRaoul On the website,
pdftk-smoser
is marked as obsolete. -
Topera over 4 yearsWorks greatly on 18.04
-
Nir over 4 yearsA handy shortcut: pdftk file* cat output mergedfile.pdf
-
Will59 about 4 yearsJust used it on 19.10, to merge and crop a series of pdf, worked like a charm.
-
Will59 about 4 yearsUsed 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 :-) -
zugzug about 4 yearsNice tool. Works like a charm on my Ubuntu 18.04 LTS
-
michael almost 4 yearsIt works great. To install on Ubuntu 20.04 LTS do:
sudo apt install pdftk-java
-
Carl Zulauf almost 4 yearsThis 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. -
Timo almost 4 years
jdk
is an overkill and should not be necessary. -
Billal Begueradj over 3 yearsThis is the best approach because the result will always be there, no bugs
-
desmond13 over 3 yearsI have the following error: Error: Failed to open PDF file: ...
-
Gireesh about 3 yearsThis is crashing in ubuntu 16.04. I have tried pdftk which is not gui based application
-
MWB about 3 yearsI'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. -
Timo about 3 yearsThis 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 about 3 years
cat
is not needed I think. -
Celal Ergün about 3 years
sudo snap install pdftk
can be used in Ubuntu 20.04 and pdftk is accepting "*.pdf" as a valid parameter. -
Frank Nocke almost 3 yearsInteresting:
pdfunite
is available by default in Ubuntu MATE 20.04. (I certainly didn't install it...) -
qwr almost 3 years
-
user140259 over 2 yearsThe sheets were returned with different sizes.
-
Giovanni Bassi over 2 yearsWorked really well, I used
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf *
(with the wildcard). Great, and open source. Thanks! -
topher217 about 2 years@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.
-
Carl Zulauf about 2 years@topher217 APT will tell you pdfshuffler is just pdfarranger. On Ubuntu 20.04 try
$ apt show pdfshuffler
and look closely. -
topher217 about 2 years@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. -
Admin almost 2 years
pdftk
does not work if there spaces in the filenames