Thursday, October 11, 2012

How to combine PDFs

Recently, I had to figure out how to join pdfs files into one. This used to be something non-trivial. Nowadays, you can use SimpleScan to scan in documents and create a multi-page PDF. But a few days ago I found myself on an older Mandriva PC with a scanner and the need to create a multi-page PDF. I scanned the pages of the documents with trusty old XSane.  Now I have the pages individually. I was thinking of something clever like opening up Scribus and pasting each image per page. I was also thinking of pasting the images in a OpenOffice document but the images would shrink too much. I gave up thinking like a Windows user and looked at the problem in it's most basic form. I could print the images into individual PDFs but then I would need to combine them together. I was thinking along the lines of printing out in postscript and then concatenating the files together. Then convert the resulting postscript file into a PDF, which is trivial.
Finally, I decided I wasn't that smart and asked Google. I found the answer here, in a Macworld article, of all places. Basically, I had to print out the pages individually as PDFs, which involves setting the printer to print to file. Then I use good old Ghostscript. The command is

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf source1.pdf source2.pdf source3.pdf etc.pdf

Replace source1.pdf, source2.pdf, source3.pdf and etc.pdf with the names of the files that I had printed earlier. Run the command and rename merged.pdf and I'm done.
Basically the command takes the list of pdf files as input and 're-prints' them out as one pdf file using the printer definition called "pdfwrite" which is a basically generates a PDF output.
Never underestimate the power of the command line tools.
Here is another tool I found to change PDFs.


  1. Anonymous10:53 AM

    hey bro, any way i can do all that you say on my laptop without doing it that way? - mal

    1. Since writing the post, I found pdftk. It's still commandline but more straighforward.
      If you are on Windows try pdftkbuilder. or better still

  2. Anonymous1:19 PM

    Thanks bro. I'm downloading from the latter. Will update on how it works out. Cheers - Mal

  3. No worries. I think I'll put up a separate post on this.

    1. Check out for pdftk


Recently Popular