Merge multiple PDFs into one file

For years I never knew how to combine multiple PDFs into one PDF file without the use of Adobe Professional. However, this can be done and can be done in Linux very very easily and of course, for free.
This process requires you to install two packages: Ghostscript and PDFtk. These packages are widely available in the repositories of your distro of choice. If you are going to install them using apt, use the following commands:
apt-get install gs
apt-get install pdftk
Alternatively, if you would rather download the packages and install them yourself, here are the links to the download pages:
Link: Ghostscript download
Link: PDFtk download
Now, open a terminal and copy and paste the following command:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=firstANDsecond.pdf -dBATCH first.pdf second.pdf
Change the name of first.pdf and second.pdf to the PDF files that you would like to merge, and change the name of firstANDsecond.pdf to the name you would like to name your merged pdf file. If you haven’t changed directories, the merged document will be created in your home directory.
This command allows you to merge more than just two documents. If you would like to merge three or more PDF files, continue to append the file names to the above command (separated by a space).

















pdfcreator is a pseudo printer that has a “wait” button. after collecting various files into the list, merge from the list of files “printed” from various apps.
Only calling ‘gs’ shouldn’t require ‘PDFtk’. That’s just another tool doing a pdf merge.
thanks, this helped us in a pinch.
and only calling pdftk woudln’t require gs.
IMO pdftk is easier to use because it was it was created for.
actually. why do you ask people to install pdftk if you are not telling them how to use it?
pdftk first.pdf second.pdf cat output firstANDsecond.pdf
Thank you very much for the great info!!
It worked perfectly.
To me the gs command was the better option, it produces a smaller PDF in the end, however it took much longer (but this was only a one time operation, so I like the smaller file size better):
gs 8MB and 5 min
PDFtk 12MB and 20 sec.
Markus
PS: I merged 10 PDF files
There are only minor issues while using gs to merge the pdf files:
I am having trouble with the unicode characters, whenever I open the resulting (merged) pdf file, I do get :
Error: Illegal entry in bfrange block in ToUnicode CMap
repeated an infinite number of times, until the pdf file is closed.
Anyone experiencing this.? How to fix it ?
You can also do this without installing or paying anything using an online tool:
The url is: http://www.MergePDF.net
Great info!! Ghostscript worked for me under Cygwin running on my Windows box!!
this kinda doesn’t work on pdf grayscale images… when i merged a few images together, the images got “inversed” black on white, white on black.. odd…
That is odd, indeed!
I wrote a shell script that uses this technique to merge a directory tree full of PDFs with bookmarks to the joined files. I use it to assemble 900 chapters into one 6000 page book.
http://github.com/bronson/pdfdir
Hope someone else finds it useful.
That’s great! Thanks for sharing the script, @bronson!
It is nice , but in the result PDF another font is used not mine.
Any hints what is wrong ?
@VS That usually happens if you don’t embed or outline your fonts. It looks for a local version of the font, and after not finding it, substitutes.
Thanks a lot for the information, worked great for me to join to pdf files that I needed urgently…
This is exactly the command I was looking for.
Thanks a lot,
THANK YOU!! I was looking for this for ages!
Thanks, that worked (merging 15 pdfs for easy searching)
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combined.pdf -dBATCH *.PDF
works fine to save typing all those file names – just cd to the right folder first and then away you go…