Skip to content
Sat, Jan 27 2007

Merge multiple PDFs into one file

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

Around The Web
Share This Post:
  • Digg
  • email
  • Facebook
  • StumbleUpon
  • Tumblr
Technology

Comments

  1. By Robert

    Well I used gs and pdftk to merge 91 pdf-files. Went well, too. Problem is every odd page is only half the size of the even numbered pages allthough the originals only differ very little in size ._.

    help please!

  2. By exactt

    also check out http://sourceforge.net/projects/pdfshuffler/ if you aren’t very fond of the command-line…

  3. By Poorna

    In case u have hundred individual files named as in1, in2, in3,…..in100 then use this command

    gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf in[1-100].pdf

    IT WORKS :)

  4. Trackback
    828 days ago
    Juntando PDF no Linux - Manoel Campos Blog

    [...] Decio Blog e Every Joe. VN:F [1.8.1_1037]por favor, aguarde…Rating: 0.0/10 (0 votes cast)VN:F [1.8.1_1037]Rating: 0 [...]

  5. By Lee

    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…

  6. By Solartraveler

    Thanks, that worked (merging 15 pdfs for easy searching)

  7. By Alex

    THANK YOU!! I was looking for this for ages!

  8. By omabil

    This is exactly the command I was looking for.
    Thanks a lot,

  9. By Moises

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

  10. By VS

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

  11. By bronson

    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.

  12. By yanger

    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…

  13. By Tom

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

  14. By Gunnsteinn Hall

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

    The url is: http://www.MergePDF.net

  15. Trackback
    1280 days ago
    b.l.o.g. » Blog Archive » Bookmarks for November 6th

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

  16. By Felipe Web User

    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 ?

  17. By Markus

    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

  18. Trackback
    1437 days ago
    Juntando vários PDFs em um só | Israel Junior

    [...] 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 [...]