Jan 052007
 

Sponsored Link

It is very useful to combine multiple PDF documents into one file. This is useful especially if you accumulate many PDFs (newsletters, bills, etc.) over time.

Preparing Your system

sudo apt-get install gs pdftk

Now we will see one example how to combine pdf files let us assume we have 1.pdf,2.pdf,3.pdf files and now we need to cobmine this files using the following command

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH 1.pdf 2.pdf 3.pdf

In the above command after “-sOUTPUTFILE=” type whatever name you want for the merged file (don’t forget to append .pdf to the end of the file name). Rename “1.pdf 2.pdf 3.pdf” to whatever your file names are (separate your file names with a space).

After you run the above command, a new PDF file called combinedpdf.pdf will be created with your individual files merged according to the order you list.

If you want to know more options available for gs command check man page

 Posted by at 9:17 am
  • versuchsanstalt

    Will the appended files be preceded by a pagebreak?

  • blah

    weiß ich leider nicht, müsstest du mal den author fragen

  • george m

    I’m a new ubuntu user. It’s dissapointing that none of the PDF gui programs in the list have this feature.

  • http://rickvanderzwet.nl Rick van der Zwet

    Works like a sharm, thanks!

  • allen

    Excellent! thanks so much!

  • Lasse

    Perfect!….just perfect. It even compresses the files a bit. Suited me just fine. Thx.

  • pem

    pdftk a.pdf b.pdf c.pdf cat output abc.pdf

    this command is easier to remember.

  • http://rickvanderzwet.nl Rick van der Zwet

    Works like a charm, thanks!

    FTI: To save some typing (filenames) you could also you shell expansions instead:
    gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH ?.pdf

  • stuffit

    thanks for that you have just saved me lots of time

  • Rick

    if you do this frequently, I’d suggest creating a simple shell script:
    #!/bin/bash
    gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combined.pdf -dBATCH $@

    save as /usr/local/bin/combinepdf, make it executable, and run it with:
    combinepdf a.pdf b.pdf c.pdf
    or even
    combinepdf `ls -1 `

  • Gerald

    Does anyone know how to make it link the files without makin a pages per file. I mean, make them all together like linking pictures. In my case I have pictures of time series and I want to put one above the other, actually I get one page after the other.

  • T. Williams

    This application sucks! I never got it to work or even come up! I’ve uninsulated it and gone with PDF Editor. Perhaps someday there will be a way to use this program without having a programing degree.

  • Sam

    Thanks alot….. God Bless

  • corey

    >T. Williams says:
    >October 29, 2010 at 11:45 pm
    >
    >This application sucks! I never got it to work or even come up! I’ve uninsulated it and gone with PDF >Editor. >Perhaps someday there will be a way to use this program without having a programing degree.

    I’m 17 and had no problem with this program. it runs in the terminal. i use ubuntu (as reference). i too found it easier to navigate to the folder then use *.pdf to combine the pdf files. other than that it is a simple copy paste from above. mine is currently still running as i have over 100megs to combine into one but i’m hoping for good results

  • Jerry

    @Rick Useful idea to encapsulate this into a script, but the argument expansion causes problems if your filenames have whitespace in them; to fix this, quote “$@” so the file reads as follows:


    #!/bin/bash
    gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combined.pdf -dBATCH "$@"

  • Frank

    An easier alternative is pdfunite (poppler). You probably already have it installed.

  • name

    Thanks for this. BTW: the ps command worked fine for me without having pdftk installed.

  • Alex

    Just superb!

  • Saheed P P

    fabulous !!! fantastic !!! stupendous !!! grateful …………