Monday, January 19, 2009

Easy way to combine pdf files

Don't you just love it when you find a good tutorial on something and instead of having 1 pdf file that contains everything, you find that each chapter has its own pdf file.  Its more of a pain to have several or more files than one big file.  

For instance, I am currently reading "How to think like a computer scientist", which is an excellent introduction into the world of Python programming.  This book, by the way is the textbook used for the MIT open courseware course "A Gentle Introduction to Programming Using Python".  The book is fabulous, but after downloading the material from MIT, I found that it contained PDF files of the books chapters, but not one with everything (which in my opinion would have been a lot more helpful). 

But, not to fret if you are using Linux (which I am, Ubuntu to be precise), as there is a program called Ghostscript which will make combining the files MUCH easier than going out and purchasing Adobe Acrobat (no need, believe me).

I had stumbled across this method on this website, which gave a very good overview of using ghostscript to combine a bunch of pdf files into one big pdf file. 

So, I set about to combine the 13 pdfs into one.  The following command was what I issued:

        gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=httlacs.pdf ch01.pdf ch02.pdf ... ch13.pdf

In this command the "..." symbolizes all of the files I listed.  Now please know that you have to list the files in the order that you want them combined.  The program will start at the first file on the left (ch01.pdf) and work through the list to the end (ch13.pdf).  When the command is done running (it took a couple of minutes to complete) I had a nice PDF by the name of httlacs.pdf that contained the entirety of the book.  Very nice and very easy if you ask me.

Hope this helps you!

No comments:

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.