Merging Multiple PDFs into one file on Ubuntu (linux)

By admin, 25 March, 2009

Today I wanted to merge two PDF files into one final PDF document. On Ubuntu, this was harder than I thought. I have done this on Windows using Adobe and it was pretty simple. I decided that I will make this post so that I can always find the command when I am looking for it. This is a command-line approach. I did not find a nice GUI approach, but if there is anyone out there who has found one, please feel free to leave a comment.

Here are the steps to install the necessary packages: sudo apt-get install gs sudo apt-get install pdftk Now here is the command that does the actual merging: gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=output.pdf -dBATCH first.pdf second.pdf

You can merge more PDFs by simply adding on a third pdf etc. It merges them in the order you put it. So second.pdf will merge after the last page of first.pdf output.pdf will contain the final PDF that you want. You should probably have all the PDFs in one directory and run the command from there although this is not necessary if you know what you are doing and you know your directory structure. Go forth and merge!

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Anonymous (not verified)

13 years 5 months ago

I don't think you need GS to do it. I installed pdftk a while back to do the same thing, though I don't remember if it pulled in GS as a dependency. Take a look at the 'cat' operation in the pdftk man page.

If there's a way to do it with stock GS, that would be very useful, as pdftk depends on gcj, which can be a pain if you're building from source.

--Andrew

Member for

16 years 4 months

Trinidad and Tobago

Actually GS is not a dependency of pdftk. I looked at the 'cat' operation but could not quite figure out how to use that command. Can you give a sample command to use it?

Not specified