Saturday, February 28, 2009

Merging PDF documents

Having its origins in the GNU community over 20 years ago, Ghostscript (gs) was designed as a free interpreter for Adobe PostScript with an intention of saving trees and named as a play of words on that. Along with providing tools for raster image processing and converting between different document formats, it also comes with a peculiar pdf/ps viewer called Ghostview (gv), which I am not sure of ever using over good old evince.

Nevertheless, I find some command line gs utils incredibly powerful. Lets say you wanted to merge two pdf files. Just say:

$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf

The options are somewhat involved and long to explain here, but you can read through the documentation. If you want to save the typing, add

$ alias mrg='$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf'

to your .bash_profile and then use

$ mrg file1.pdf file2.pdf

to get a merged output.pdf. Pure GNU.

1 comment: