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

  19 Responses to “Combine multiple PDFs into one file in Ubuntu Linux”

  1. Will the appended files be preceded by a pagebreak?

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

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

  4. Works like a sharm, thanks!

  5. Excellent! thanks so much!

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

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

    this command is easier to remember.

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

  9. thanks for that you have just saved me lots of time

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

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

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

  13. Thanks alot….. God Bless

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

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

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

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

  18. Just superb!

  19. fabulous !!! fantastic !!! stupendous !!! grateful …………

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>