Tuesday, December 11, 2007

Merging PDFs with ghostscript

Just a quick tip tonight, mostly for Linux/Unix users (though there is no reason the clever Windows users couldn't use this too).
As you may already be aware, ghostscript is a (free) tool for working with Adobe's pdf and postscript formats. Among the uses I have found for it is concatenating pdf files (in this case chapters of an ebook to make it easier to search the whole thing). While you can do this with Acrobat reader in Windows, it is a quick single liner on the command line using ghostscript:
gs -DBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf... fileN.pdf

If you're like me and have your source pdfs scattered around a bunch of subdirectories you can try this command (for the BASH shell)

find | grep -i pdf |xargs gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf

You might want to try the command first without the call to xargs and gs (ghostscript) to make sure only the files you want are selected.

Note: I have talked about ghostscript before

No comments: