Sunday, 19 January 2014

Combining multiple PDF documents into one

A number of times I have faced the requirement of combining multiple PDF files into a single file. Doing that is fairly simple actually. It can be done using a number of tools. Two ways of doing it using tools very common on linux systems are as follows.
A lot many systems have imagemagick installed.  Using it is so simple that I use it as my default tool for this purpose.

convert file1.pdf /path/to/file2.pdf /destination/path/store.pdf

It takes a lot of options. For PDFs containing images, it is better to specify a quality parameter.

convert -quality 100 mine1.pdf mine2.pdf merged.pdf
Ghostscript is also very commonly found package in linux systems. Its usage is a little more obscure. However, it is very fast. I use it when I need to get PDF files of reduced size.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input1.pdf input2.pdf

The above however reduces image quality badly. To get decent image quality with a little larger PDFs, we can use the following.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input1.pdf input2.pdf

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=output.pdf input1.pdf input2.pdf

No comments: