Combine multiple PDFs into one file in Ubuntu Linux

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

19 thoughts on “Combine multiple PDFs into one file in Ubuntu Linux

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

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

  3. 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 `

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

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

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

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

Leave a comment

Your email address will not be published. Required fields are marked *