Friday, October 9th, 2009

Merge multiple PDFs into one file

January 27, 2007 by admin  
Filed under How To

Merged PDFs
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).

  • StumbleUpon
  • Digg
  • Facebook
  • Mixx
  • Google
  • TwitThis
  • Reddit
  • Yahoo! Buzz
  • Slashdot


22 Responses to “Merge multiple PDFs into one file”
  1. sbt says:

    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.

  2. db says:

    Only calling ‘gs’ shouldn’t require ‘PDFtk’. That’s just another tool doing a pdf merge.

  3. mike says:

    thanks, this helped us in a pinch.

  4. ubuntero says:

    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

  5. Vivek Thomas says:

    Thank you very much for the great info!!

    It worked perfectly.

  6. Markus says:

    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.
    PS: I merged 10 PDF files

  7. Felipe Web User says:

    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 ?

  8. Gunnsteinn Hall says:

    You can also do this without installing or paying anything using an online tool:

    The url is:

  9. Tom says:

    Great info!! Ghostscript worked for me under Cygwin running on my Windows box!!

  10. yanger says:

    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…

  11. bronson says:

    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.

    Hope someone else finds it useful.

  12. VS says:

    It is nice , but in the result PDF another font is used not mine. :(
    Any hints what is wrong ?

    • Andy says:

      @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.

  13. Moises says:

    Thanks a lot for the information, worked great for me to join to pdf files that I needed urgently…


Check out what others are saying about this post...
  1. 如何合并多个 PDF 文档 | LinuxDig says:

    [...] New Linux User, [...]

  2. how to combine pdf files says:

    [...] use of Adobe Professional. However, this can be done in Linux very easily and of course, for free. PDF Writer, PDF Form Filler, PDF Page Number, PDF Split …Split pdf file into multiple [...]

  3. Juntando vários PDFs em um só | Israel Junior says:

    [...] isso com o Ghostscript. Como a memória anda fraca nesses dias consultei o oráculo Google, que me respondeu: $ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=saida.pdf -dBATCH entrada1.pdf [...]

  4. b.l.o.g. » Blog Archive » Bookmarks for November 6th says:

    [...] Merge multiple PDFs into one file – Use ghostscript and pdftk to merge multiple pdfs into one. [...]

  5. Mehrere .pdf-Dateien unter Linux zusammenfügen « 23Quadrat says:

    [...] [via] [...]

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

About Us | Advertise with us | Blog for EveryJoe | Privacy Policy | Terms of Use
Get This Theme | Sitemap

All content is Copyright © 2005-2009 b5media. All rights reserved.