Tuesday, October 19, 2010

Merging several PDF files in Linux

I often google on "How to merge multiple files into a single PDF". Well, it is quite a simple task to put together, or combine, PDF files without installing "Pdftk". All you need is just the GhostScript package. Here is a sample command taken from one of my bash-scripts:

#!/bin/bash
gs \
    -dBATCH \
    -dNOPAUSE \
    -q \
    -sDEVICE=pdfwrite \
    -r600x600 \
    -sPAPERSIZE=a4 \
    -sOutputFile=merged-file.pdf \
    file-1.pdf \
    file-2.pdf \
    file-3.pdf