How to merge multiple PDFs into single PDF!

It is one problem many of us face when we deal with documents - PDFs. The biggest advantage of PDF file format is also its biggest problem - you cannot edit a PDF file. Yes, I know there are software available - both free and paid which allow you to edit PDFs but then they are all crude and in the end, the edited PDF would not look the way you want them to look! Unless you have paid heavy amount of sum to Adobe, you are basically stuck with the way PDF is looking and behaving. 

One way to create a PDF is to make your own document, get yourself a software which installs a virtual printer and use it to convert your document into a PDF! That way, when you want to update the PDF, all you have to do is to edit the parent (original) document and export it to PDF again. Job done! But then non of us create all the PDFs we get! We get multiple PDFs from different people and websites. When talking about websites, there are people who would save some interesting or useful web pages as PDF files on their desktop, and I belong to that category. 

But once you have 40 PDF files which fall into one category, you have a problem. Opening all those 40 files and going one after another is a tedious task. Another such example is when you got a few pages from someone's notebook scanned and sent to you in PDF format. So when you want to go to page number 23 from 100 files, you would go and open a file named something like scan00568.pdf and that is cumbersome by all means. Merging PDFs is one thing any regular user would want time and again and for various reasons depending on who you he is and what he does. Nonetheless, there are solutions; and why go far when you have your Linux box? (or even Windows!)

so here is a command which gets it done, the real easy way (unless you fall into mental trauma when someone mentions terminal):

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=final.pdf scan00567.pdf scan00568.pdf scan00569.pdf scan00570.pdf

Note that for that command to run, the gs command (GPL Ghostscript package) must be available. The package comes pre-installed with all the famous Linux distributions! Now we show you what that command means:

  1. gs: It is the command.
  2. -dBATCH: This option tells gs that the processing has to be done in a batch for all the files.
  3. -dNOPAUSE: This option tells gs not to pause after processing every page in documents as it goes. 
  4. -q: This tells the GPL GhostScript to keep its mouth shut and do the job; which means no output on screen!
  5. -sDEVICE=pdfwrite: This argument selects the output device as pdfwrite. There are hell lot of devices available from PDF and PS to JPEG and PNGs for output. Unless you are a person who deals with typesetting using software, chances are you wouldn't understand 90% of them!
  6. scanXXXXX.pdf: these are the files which gs will process (in that order). So if you put scan00568.pdf before scan00567.pdf then that is how they will appear in the output file (final.pdf). 

That's pretty much it! However, if you wanted to merge all PDF documents in one single directory in alphabetical order into a single PDF, just replace the list of filenames with *.pdf. It goes without saying that the time taken to merge PDFs would depend on how many and how complicated the documents are! Now, isn't that easy? Need to buy some software, eh?